芹菜计划列表返回无

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Seasonal Decomposition of Time Series by Loess with Python(Loess 用 Python 对时间序列进行季节性分解)
Resample a time series with the index of another time series(使用另一个时间序列的索引重新采样一个时间序列)
How can I simply calculate the rolling/moving variance of a time series in python?(如何在 python 中简单地计算时间序列的滚动/移动方差?)
How to use Dynamic Time warping with kNN in python(如何在python中使用动态时间扭曲和kNN)
Keras LSTM: a time-series multi-step multi-features forecasting - poor results(Keras LSTM:时间序列多步多特征预测 - 结果不佳)
Python pandas time series interpolation and regularization(Python pandas 时间序列插值和正则化)