Skip to content

chord not working on celery4 + rabbitmq #3330

Closed

Description

@bruno-rino

The chord given as an example in the docs http://docs.celeryproject.org/en/master/userguide/canvas.html#chords doesn't work with rabbitmq. It works fine with redis and CELERY_ALWAYS_EAGER.

from __future__ import absolute_import, division, print_function
from celery import Celery, chord, chain, group

app = Celery('chords', backend='amqp', broker='amqp://')
# app = Celery('chords', backend='redis://', broker='redis://')
# app.conf.CELERY_ALWAYS_EAGER = True

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

@app.task
def tsum(numbers):
    return sum(numbers)

if __name__ == '__main__':
    result = chord(add.s(i, i)
                   for i in xrange(100))(tsum.s())
    print(result.get())

The workers keep logging this message every 2 seconds:

Task celery.chord_unlock[023e5274-375b-4552-bc96-ff22be9d9aca] retry: None

I am using python 2.7.10, RabbitMQ 3.6.1, Redis 3.2.1.

Activity

  1. added this to the v4.0 milestone on Jul 20, 2016
  2. ask commented on Sep 8, 2016

    @ask
    Contributor

    Thanks! This definitely sorted out a really bad issue where .retry would send the message back to the wrong exchange.

    There's still an issue with the amqp result backend though, probably something I missed when
    I converted the AMQP backend to inherit from the RPC backend (previously it was the other way around).

    The issue is not with chord specifically in this case, the issue seems to be with joining any group:

    >>> res = group(add.s(i, i) for i in range(10))()
    [0, 2, 4, 6, 8, 10, 12, 14, 16, None]
    >>> res.ready()
    False

    If the result wasn't ready, .get() should not return and none of the values should be None.

    Good news: I fixed the RPC result backend, Bad news: I broke the amqp result backend.

    The "amqp" result backend is deprecated now and nobody should be using it, but should definitely
    fix this issue. I'll be working on it.

  3. ask commented on Sep 8, 2016

    @ask
    Contributor

    Works for me now! The async backends actually start consuming results from when you call the task, and the old deprecated amqp result backend require messages not to be acked when polling for status (e.g. result.ready(), since multiple consumers may need the same result (e.g chords poll result s in a task retry loop, so cannot lose result messages between the loop).

    Much easier to just revert the amqp result backend to the old behavior, since we don't want people to be using it anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions