Mridang Agarwalla Mridang Agarwalla - 2 years ago 183
Python Question

How can I run a celery periodic task from the shell manually?

I'm using celery and django-celery. I have defined a periodic task that I'd like to test. Is it possible to run the periodic task from the shell manually so that I view the console output?

Answer Source

Have you tried just running the task from the Django shell? You can use the .apply method of a task to ensure that it is run eagerly and locally.

Assuming the task is called my_task in Django app myapp in a tasks submodule:

$ python shell
>>> from myapp.tasks import my_task
>>> eager_result = my_task.apply()

The result instance has the same API as the usual AsyncResult type, except that the result is always evaluated eagerly and locally and the .apply() method will block until the task is run to completion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download