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?
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With