Celery scheduled list returns None(芹菜计划列表返回无)
问题描述
我对 Celery 还很陌生,我一直在尝试设置一个简单的脚本来安排和取消安排任务.但是我觉得我遇到了一个奇怪的问题.我有以下设置
I'm fairly new to Celery and I've been attempting setup a simple script to schedule and unschedule tasks. However I feel like I'm running into a weird issue. I have the following setup
from celery import Celery
app = Celery('celery_test',
broker='amqp://',
backend='amqp')
@app.task
def add(x, y):
return x + y
我很好地启动了我的 celery 服务器,并且可以添加任务.现在,当我想获取活动任务列表时,事情似乎变得很奇怪.当我使用检查来获取计划任务列表时,它只工作一次,然后每次都返回无.
I start up my celery server just fine and can add tasks. Now when I want to get a list of active tasks things seem to get weird. When I goto use inspect to get a list of scheduled tasks it works exactly once then returns None every time afterwards.
>>> i = app.control.inspect()
>>> print i.scheduled()
{u'celery@mymachine': []}
>>> print i.scheduled()
None
>>>
无论我是否添加任务都会发生这种情况.我想找到一种方法来始终如一地从我的芹菜队列中返回任务列表.我想这样做,这样我就可以找到以前排队的任务,撤销它,然后重新安排它.我觉得我在这里缺少一些基本的东西.
This happens whether I add tasks or not. I want to find a way to consistently return a list of tasks from my celery queue. I want to do this so I can find a previously queued task, revoke it, and reschedule it. I feel like I'm missing something basic here.
推荐答案
要重复调用以获取队列中的任务列表,您必须创建 Celery 对象的新实例.我试图通过调试调用 ./manage.py celery inspect scheduled 执行的代码来弄清楚为什么有必要,但没有任何运气.也许有人会有更多的经验,并在这个答案中添加一些额外的信息.
To repeat call to get list of tasks in queues you have to create new instance of Celery object. I was trying to figure out why it's necessary by debugging code executed by calling ./manage.py celery inspect scheduled but without any luck. Maybe someone will have more experience with that and add some additional informations to this answer.
试试这个简单的片段来检查计划任务列表:
Try this simple snippet for checking list of scheduled tasks:
from celery import Celery
def inspect(method):
app = Celery('app', broker='amqp://')
return getattr(app.control.inspect(), method)()
print inspect('scheduled')
print inspect('active')
这篇关于芹菜计划列表返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:芹菜计划列表返回无
基础教程推荐
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
