1、启动flower监控程序
1、test_plt的app下新建tasks.py文件
from celery import shared_task
@shared_task()
def debug_task(a, b):
return a+b
2、命令行启动一个任务
import os, django
os.environ['DJANGO_SETTINGS_MODULE'] = "auto_test_platform.settings"
django.setup()
from test_plt.tasks import task_plus
task_plus.delay(3,5)
预期:<AsyncResult: 07f6388c-77d4-4d78-97cb-a2b87461a292>
2、启动监控程序: Celery -A auto_test_platform flower --port=5566
2、启动beat周期程序
1、在django项目的settings.py里面添加beat的配置选项
INSTALLED_APPS = [
'django_celery_beat',
]
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
2、添加完成后,数据库建表:py manage migrate 3、启动beat周期任务 Celery -A auto_test_platform beat -l info
3、启动flower报错
报错内容:
[W 220709 12:21:48 inspector:42] Inspect method conf failed
[W 220709 12:21:48 inspector:42] Inspect method stats failed
[W 220709 12:21:48 inspector:42] Inspect method registered failed
[W 220709 12:21:48 inspector:42] Inspect method revoked failed
[W 220709 12:21:48 inspector:42] Inspect method active failed
[W 220709 12:21:48 inspector:42] Inspect method active_queues failed
[W 220709 12:21:48 inspector:42] Inspect method scheduled failed
[W 220709 12:21:48 inspector:42] Inspect method reserved failed
解决办法: 原因是我没有启动 celery 的worker程序,正确的操作步骤: 1、启动 django 进程:py manage.py reserver 8000 2、启动 rabbitmq 进程(windows服务) 3、启动 celery 的 worker 进程:Celery -A auto_test_platform worker -l info -P eventlet 4、启动 celery 的 flower 监控进程:Celery -A auto_test_platform flower --port=5566 5、启动 celery 的 beat 周期任务进程:Celery -A auto_test_platform beat -l info
|