芹菜预定列表返回无 [英] Celery scheduled list returns None

查看:69
本文介绍了芹菜预定列表返回无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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服务器并可以添加任务。现在,当我想获取活动任务列表时,事情似乎变得很奇怪。当我转到使用inspect获取计划任务的列表时,它仅工作一次,然后每次都返回None。

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 schedule 调试执行的代码来弄清楚为什么有必要,但是没有任何运气。也许有人会对此有更多的经验,并在此答案中添加一些其他信息。

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')

这篇关于芹菜预定列表返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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