When deploying a Python application you sometimes have to restart celery. If there is a long-running task you might not want to kill that task, but rather wait 'till the tasks have finished.
This function will pause the accepting of new tasks and wait 'till all tasks are finished.
from celery import Celery
from celery.app.control import Control
def celery_check():
app = Celery("app") # Name of the main module
control = Control(app)
control.cancel_consumer("celery") # queue name, must probably be specified once per queue, but we use a single queue
inspect = control.inspect()
while True:
active = inspect.active()
if len(active.items()) > 0:
seconds = 10
time.sleep(seconds)
else:
break
Top comments (0)