I have a task in celery that can only be ran once because it needs to import a new copy of my module and sub modules from a different folder each time it runs. Celery does not handle this well, it holds on to the modules from the previous run. It seems like the only solution is to shut off the worker after the task is complete.
However, when trying to turn it off, the message goes back on the queue.
I have tried
- app.control.shutdown(destination=[hostname]) this shuts down the worker after the task finishes successfully but still puts the task back on the queue app.control.broadcast('shutdown',destination=[hostname]) this has the same affect as the above command
- revoke() revoke allows the task to be ignored but it still sits on the queue.
- raise IGNORE() and REJECT() exceptions to stop the task if redilivered but this does not solve the problem of redelivery in the first place.
Note:
I am using rabbitmq as the message broker. This is a long running task (hours) and we only want one task to be run at a time on each worker. No prefetching, So concurrency is set to 1 and ack_late = True.