Search code examples
pythondjangodjango-admincelerydjcelery

What is the difference between Revoke, Terminate and Kill when using djcelery?


I am using djcelery and django's admin site. If I want to stop a djcelery task that has started, do I use revoke, terminate or kill and what is the difference?


Solution

  • You should use terminate to kill an already started task.

    revoke:

    >>> from celery.task.control import revoke
    >>> revoke(task_id)
    

    When a worker receives a revoke request it will skip executing the task, but it won’t terminate an already executing task.

    terminate:

    >>> from celery.task.control import revoke
    >>> revoke(task_id, terminate=True)
    

    If terminate is set the worker child process processing the task will be terminated. The default signal sent is TERM. Terminating a task also revokes it.

    kill:

    This is different from the above two. KILL is used to kill workers

    ps auxww | grep 'celery worker' | awk '{print $2}' | xargs kill -9