I have a signals.py
inside my project/jobs
app.
This is the file:
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
is fired while task_postrun_handler
is not.
signals.py
is imported by my AppConfig
, inside the ready()
function.
This is my celery config:
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?
They are both events under the Task category, so I can't see why one works and the other does not.