如何从shell手动运行芹菜周期性任务? [英] How can I run a celery periodic task from the shell manually?
问题描述
从Django shell的任务?您可以使用任务的 .apply
方法来确保它在本地运行。
假设任务在$ code>任务中的Django应用程序 myapp
中称为 my_task
子模块:
$ python manage.py shell
>>>从myapp.tasks导入my_task
>>> eager_result = my_task.apply()
结果实例与通常的 AsyncResult
类型,除了结果总是被热切地和本地评估,并且 .apply()
方法将阻塞,直到任务运行到完成。
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?
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.
这篇关于如何从shell手动运行芹菜周期性任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!