如何从shell手动运行芹菜周期性任务? [英] How can I run a celery periodic task from the shell manually?

查看:204
本文介绍了如何从shell手动运行芹菜周期性任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用芹菜和芹菜。我定义了一个我想测试的定期任务。可以手动运行shell的周期性任务,以便查看控制台输出吗?

解决方案

从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆