Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery check pending tasks number before specified taskid

Does celery support returning pending tasks number before given task id?

For example, without celery worker started, I push task1, task2, task3, all the three are pending, now, what I wanna is, if I give task3, it tells me there are 2 pending tasks before 3.

I use celery celery 4.1, rabbitmq 3.5.4 as broker, and redis 3.2.9 as result backend.

Although I can get rabbit queue depth by management API(e.g. get_queue_depth from pyrabbit package), this results the whole queue depth, not pending number before specified task id.

And I know I could maintain a queue managing pushed task ids by myself.

But I wanna if there is any easy way by celery or rabbitmq itself.

Thanks.

like image 230
Storm Avatar asked Nov 08 '22 16:11

Storm


1 Answers

I'm not sure if it answer your question but there is control client that can help you to inspect reserved tasks, active tasks and so on..

i = app.control.inspect()
i.reserved()

#output:
[{'worker1.example.com':
    [{'name': 'tasks.sleeptask',
      'id': '32666e9b-809c-41fa-8e93-5ae0c80afbbf',
      'args': '(8,)',
      'kwargs': '{}'}]}]

for more info: http://docs.celeryproject.org/en/latest/userguide/workers.html#dump-of-reserved-tasks

You can also monitor/inspect from command line: http://docs.celeryproject.org/en/latest/userguide/monitoring.html#commands

like image 86
ItayB Avatar answered Nov 15 '22 11:11

ItayB