[英]celery trying shutdown worker by raising SystemExit in task_postrun signal but always hangs and the main process never exits
[英]Celery @task_postrun.connect not firing
我的project/jobs
應用程序中有一個signals.py
。 這是文件:
from celery.signals import task_postrun, after_task_publish
from project.jobs.models import JobModel, JOB_STATUS_CHOICES
@after_task_publish.connect
def task_sent_handler(sender=None, headers=None, body=None, **kwargs):
info = headers if 'task' in headers else body
print('after_task_publish for task id {info[id]}'.format(info=info,))
@task_postrun.connect
def task_postrun_handler(task_id=None, **kwargs):
print('CONNECT', task_id)
JobModel.objects.filter(task_id=task_id).update(status=JOB_STATUS_CHOICES.SUCCESS)
task_sent_handler
被激發,而task_postrun_handler
沒有被激發。
signals.py
是由我的AppConfig
導入的ready()
函數中的。
這是我的芹菜配置:
CELERY_BROKER_URL = env('CELERY_BROKER_URL')
CELERY_SEND_EVENTS = True
CELERY_RESULT_BACKEND = env('CELERY_RESULT_BACKEND')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
關於為何
task_postrun
任何建議?
它們都是“任務”類別下的事件,所以我看不到為什么一個起作用而另一個不起作用。
配置正確,系統重新啟動后,以某種方式在celery任務日志上開始顯示CONNECT
打印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.