Varlor
Varlor

Reputation: 1471

Python: Celery inspect

I found some related questions but nothing that describes exactly my problem. So I can inspect my queue with a code like that:

from celery.task.control import inspect
#inspect(['my_queue']), with a list instead of a str, should work! 
i = inspect(['my_queue'])
print(i.active())  #  get a list of active tasks
print(i.registered()) # get a list of tasks registered
print(i.scheduled()) # get a list of tasks waiting
print(i.reserved()) #tasks that has been received, but waiting to be executed

But somehow, for every second execution the method returns a empty task list. Sometimes I also get a Reset Connection Error. Some ideas why this happes? Is there something like a interval, where workers fill there active tasks list or something like that?

Upvotes: 4

Views: 3617

Answers (1)

DejanLekic
DejanLekic

Reputation: 19797

I assume the code you wrote above is not how the actual application looks (it can't work without a Celery object). - The only explanation is that you have some connectivity issues, otherwise it should work every time you run, unless genuinely there are no tasks to report. In other words - the cluster is idle.

Keep in mind that inspect broadcasts a message to all the workers and waits for their replies. If some of them times out for whatever reason(s), you will not see that worker in the output. If it happens that only that worker was busy, you may end up with an empty list of tasks.

Try to call something like celery -A yourproject.celeryapp status to see if your workers are responsive, and if everything is OK run your script. - It should work.

Upvotes: 3

Related Questions