Git Product home page Git Product logo

fastapi-tortoise's Introduction

描述

tortoise 使用aiomysql驱动程序

依赖包

mysql数据库参数修改

下述参数不修改,会导致同步数据库结构时报错

vi /etc/mysql/mysql.confs.d/mysqld.cnf
max_allowed_packet = 25600

初始化数据库结构

aerich init -t settings.TORTOISE_ORM
aerich init-db

日志模块

AuthenticationUser中间件,记录了所有对服务端的请求操作,并保存导数据,该操作会影响服务的性能

Test model为测试数据模型

test路由中包含了覆盖路由的写法和临时内存路由MemoryCRUDRouter类的demo

backend

  • 如需在后端运行,则需要在run.py中添加对应方法
  • 并且需要在该方法上添加装饰器@typer_app.command()
  • 然后运行:python run.py --help

服务的运行

fastapi的运行

  • 调试模式下: python run asgi.py
  • 非调试模式下:gunicorn -c gunicorn.conf.py asgi:app

后端脚本服务的运行

  • 通过docker-compose 指定supervisor-all直接拉起来所有脚本服务
  • supervisor守护指定的后端服务
      cp ./backend/supervisor/*.confs /etc/supervisor/confs.d/ 
      supervisorctl update 
      supervisor restart log 启动指定脚本服务

添加pylint检查代码

pip install pylint
pylint --rcfile=.pylintrc app

celery

  • celery对目录结构的要求十分严格
  • windows机器上必须加上-P eventlet启动,否则会出错,
  • -n 指定当前worker名字,
  • -Q 指定该worker监听一个或多个任务队列。

常用方法

建议使用 apply_async

  • delay 方法仅允许方法传参,不允许其他参数传递
  • apply 在本地执行此任务,不走消息队列,通过阻塞直到任务返回。
  • apply_async, 发送任务到消息队列,异步完成任务;
  • celery_app.send_task, 可以执行未在 Celery 中进行注册的任务。

启动命令

celery -A backend.celery.celery_app worker -l info -P eventlet -n win_default
celery -A backend.celery.celery_app worker -l info -P eventlet -n win_music -Q musice
celery -A backend.celery.celery_app worker -l info -P eventlet -n win_video -Q video

检查celery配置

python -m  backend.celery.celery_config
Eventlet

利用协程编写的高度可扩展的,非阻塞I/O python Lib,不适用于CPU密集型操作

Gevent

是一个基于 greenlet 的 Python 的并发框架,以微线程greenlet为核心, 使用了epoll事件监听机制以及诸多其他优化而变得高效。

启动命令
  • -b: 指定不同的broker地址
  • worker -c: 指定并发数,默认为该机器上的CPU数
  • worker --help: worker 命令
启动flower
celery -A backend.celery.celery_app flower --conf=backend\\celery\\celery_config.py

rabbitmq

rabbitmq-plugins list
rabbitmq-plugins enable rabbitmq_management

fastapi-tortoise's People

Contributors

douyahu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.