There is no list of planned celery lists

I am new to Celery and I was trying to set up a simple script for scheduling and scheduling tasks. However, I feel that I am confused by a strange problem. I have the following setting

from celery import Celery
app = Celery('celery_test',
             broker='amqp://',
             backend='amqp')

@app.task
def add(x, y):
    return x + y

I start my celery server very well and can add tasks. Now, when I want to get a list of active tasks, everything looks strange. When I use the inspector to get a list of scheduled tasks, it works exactly once, and then returns None every time after that.

>>> i = app.control.inspect()
>>> print i.scheduled()
{u'celery@mymachine': []}
>>> print i.scheduled()
None
>>>

This happens if 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 in order to find a previously set task, cancel it and transfer it. I feel that I am missing something basic.

+4
2

, , Celery. , , , ./manage.py celery inspect scheduled, . , - .

:

from celery import Celery

def inspect(method):
    app = Celery('app', broker='amqp://')
    return getattr(app.control.inspect(), method)()

print inspect('scheduled')
print inspect('active')
+5

daniula,

django-celery-rabbitmq, ... :

from celery import Celery

def inspect(method):
    app = Celery('app', broker='amqp://')
    inspect_result = getattr(app.control.inspect(), method)()
    app.close()
    return inspect_result

print inspect('scheduled')
print inspect('active')

, app.close() rabbitmq, (), , , .

+4

Source: https://habr.com/ru/post/1544686/


All Articles