How to undo the Celery task when deploying to Heroku

When my new versions of my django application are deployed to heroku, the workers are forced to restart. I have some lengthy tasks that need to do some cleanup before they are killed.

I tried to register a worker_shutdown hook, which not everyone calls a call.

I also tried responding to Notify the celery task of closing the desktop , but I don’t understand how to abort the task from this context by calling celery.task.control.active () throws an exception (celery no longer works).

Thanks for any help.

+4
source share
1 answer

If you control the deployment, maybe you can run the script that executes Control.broadcast into a user command that you can advance in advance and only after receiving the necessary answers (you have to implement this logic), will you continue the deployment (or raise a TimeoutException)?

In addition, celery already has a predefined command to complete the work , which I assume that you can overload your instance or subclass of the worker. The advantage of the commands is the transfer of the Panel instance, which allows access to the consumer . That should expose a lot of control right there ...

0
source

Source: https://habr.com/ru/post/1437684/


All Articles