Also you can use an AbortableTask
. I think this is the best way to
stop task gracefully.
http://docs.celeryproject.org/en/latest/reference/celery.contrib.abortable.html
from celery.contrib.abortable import AbortableTask
from proj.celery import app
@app.task(bind=True, base=AbortableTask)
def abortable_task(self):
while not self.is_aborted():
print 'I am running'
print 'I was aborted!'
If you save id task in somewhere you can call this whenever you want.
from celery.contrib.abortable import AbortableAsyncResult
abortable_task = AbortableAsyncResult(task_id)
abortable_task.abort()