Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 537
Mridang Agarwalla Avatar asked Oct 15 '12 16:10

Mridang Agarwalla


People also ask

How do I schedule a task in Django Celery?

First, open a new shell or window. In that shell, set up the same Django development environment - activate your virtual environment, or add things to your Python path, whatever you do so that you could use runserver to run your project.

Does Celery run tasks in parallel?

Demonstration of a task which runs a startup task, then parallelizes multiple worker tasks, and then fires-off a reducer task. If passing results around would be important, then could use a chord instead for task2 and task3 .


1 Answers

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 manage.py 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.

like image 69
Platinum Azure Avatar answered Sep 22 '22 21:09

Platinum Azure