Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using django-celery chord, celery.chord_unlock keeps executing forever not calling the provided callback

I'm using Django Celery with Redis to run a few tasks like this:

header = [
    tasks.invalidate_user.subtask(args = (user)),
    tasks.invalidate_details.subtask(args = (user))
]

callback = tasks.rebuild.subtask()

chord(header)(callback)   

So basically the same as stated in documentation.

My problem is, that when this task chord is called, celery.chord_unlock task keeps retrying forever. Tasks in header finish successfully, but because of chord_unlock never being done, callback is never called.

Guessing that my problem is with not being able to detect that the tasks from header are finished, I turned to documentation to look how can this be customized. I've found a section, describing how the synchronization is implemented, there is an example provided, what I'm missing is how do I get that example function to be called (i.e. is there a signal for this?).

Further there's a note that this method is not used with Redis backend:

This is used by all result backends except Redis and Memcached, which increment a counter after each task in the header, then applying the callback when the counter exceeds the number of tasks in the set.

But also says, that Redis approach is better:

The Redis and Memcached approach is a much better solution

What approach is that? How is it implemented?

So, why is chord_unlock never done and how can I make it detect finished header tasks?

I'm using: Django 1.4, celery 2.5.3, django-celery 2.5.5, redis 2.4.12

like image 808
Martin Tóth Avatar asked May 03 '12 20:05

Martin Tóth


1 Answers

You don't have an example of your tasks, but I had the same problem and my solution might apply.

I had ignore_result=True on the tasks that I was adding to a chord, defined like so:

@task(ignore_result=True)

Apparently ignoring the result makes it so that the chord_unlock task doesn't know they're complete. After I removed ignore_result (even if the task only returns true) the chord called the callback properly.

like image 172
Chris Martin Avatar answered Sep 28 '22 07:09

Chris Martin