Notify or callback flask after remote celery worker is completed Notify or callback flask after remote celery worker is completed flask flask

Notify or callback flask after remote celery worker is completed


One way to do this is to have Celery write its result in a database table, and use Flask to poll for the result of the task by repeatedly querying the database. A similar construct might be to keep a register of completed tasks in Redis, but the gist would be the same.

Do you want to trigger a completion message to the user? If you can notify by email/text message, you could just let Celery handle that of course.

If you need to kickstart some Flask process - and it really needs to be inside Flask's ecosystem for some reason - use the worker with the requests module to call to an endpoint that Flask is listening to.


I solved this problem using @after_task_publish from celery signals.The code snippet is as follows:-

@after_task_publish.connect(sender=<registered_celery_task>)def testMethod2(sender=None, headers=None, body=None, **kwargs):    #callback body

The testMethod2 will be called after the celery worker is completed on the remote machine.Here I can access the result of celery worker using headers parameter.