1

I'm unable to get the list of the tasks (actives, scheduled ..) in Celery.

With django, my web application send a task with celery each time the url is asked with :

tasksend = calcul.delay()

I don't want to launch this calcul if it is already in progress in celery.

So, I want to list the tasks Received by Celery and not yet finished : if my 'calcul' task is already in progress, i will then be able not to ask again for calcul.delay()

I already search a lot and the responses in Retrieve list of tasks in a queue in Celery are not good for my celery version.

I use : - django 2.0.13 - python 3.4.2 - celery v4.3.0 with redis

I already tried :

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

and print( inspect('active') ) always return None (the same result is achieved with 'registered')

I would like to be able to get the name of the task in progress and scheduled in celery, any idea?

devdob
  • 1,404
  • 12
  • 13
G.Lebret
  • 2,826
  • 2
  • 16
  • 27

1 Answers1

0

I got into the same issue before, this code below is what I used to inspect my tasks.

i = app.control.inspect()

if i.active():
    for k, v in i.active().items():
        print(len(i.active()))
        print(len(v))

I was using Rabbitmq here for my queue instead of Redis, not sure if this could make any difference, but the celery wrapper "should" take care of it.

Hope this helps!

devdob
  • 1,404
  • 12
  • 13
  • Thanks for your answer, but I tested and current_app.control.inspect().active() is always empty (even if i have a lot of task waiting and executing). Which version of celery do you use ? What did you define as app ? – G.Lebret Aug 24 '19 at 03:20
  • What is your current app defined as? And where is it defined? – devdob Aug 24 '19 at 08:57