Search code examples
pythondjangocelerycelery-task

run celery task using a django management command


I'm trying to run a task, using celery 3.1, from a custom management command.

If I call my task from a view it works fine but when starting the same task from my management command, the task will only run synchronous in current context (not async via celery).

I don't have djcelery installed.

What do I need to add to my management command to get async task processing on command line?


Solution

  • Executing Celery tasks from a command line utility is the same as executing them from views. If you have a task called foo, then in both cases:

    • Calling foo(...) executes the code of the task as if foo were just a plain Python function.

    • Calling foo.delay(...) executes the code of the task asynchronously, through a Celery worker.