芹菜@task_postrun.connect 没有开火

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 由我的 AppConfigready() 函数中导入。

这是我的芹菜配置:

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'

Any suggestions as to why task_postrun may not be fired?

它们都是任务类别下的事件,所以我不明白为什么一个有效而另一个无效。

配置正确,系统重启后,CONNECT 打印开始出现在 celery 任务日志中..