1.创建celery文件夹

 2.新建main.py和config.py文件

 3.在main.py设置celery配置文件:如下

  from celery import Celery

  import os

  导入应用设置文件(django)

  

if not os.getenv('DJANGO_SETTINGS_MODULE'):
os.environ['DJANGO_SETTINGS_MODULE'] = '配置文件名'

实例化文件
app = Celery('随便起名字')
导入celery配置文件
app.config_from_object('config配置文件')
导入要执行的任务文件夹,会自动在文件下寻找tasks.py文件,并且执行文件里面的装饰器@app.tasks(name='函数名')装饰的函数.
app.autodiscover_tasks('要执行的任务文件夹')

启动方法:

  celery -A celery_tasks.main worker -l info  可以查看信息

相关文章:

  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-02-10
  • 2021-10-14
  • 2022-02-23
猜你喜欢
  • 2021-07-12
  • 2021-12-31
  • 2021-08-08
  • 2022-12-23
  • 2021-08-07
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案