Skip to content

Nested chord body not sent to worker when using nested chords in Celery 4.0.0rc3 #3323

Closed

Description

@aauroy

When nesting three-level depth chords (the construct is shown below), the body of the "middle chord" (the B task body) does not seem to be sent to the worker.

chord([
    chord([
        chord([
            task
        ], body=A)
    ], body=B)
], body=D)

I tested this kind of construct against Celery 3.1.23 and it worked fine.

celery report output
➜  celery -A tasks report

software -> celery:4.0.0rc3 (0today8) kombu:4.0.0rc3 py:3.5.1
            billiard:3.5.0.0rc2 py-amqp:2.0.3
platform -> system:Darwin arch:64bit imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:redis://192.168.99.100:6379/0

CELERY_RESULT_BACKEND: 'redis://192.168.99.100:6379/0'
BROKER_URL: 'amqp://guest:********@192.168.99.100:5672//'
CELERY_TIMEZONE: 'Europe/Paris'
CELERYD_PREFETCH_MULTIPLIER: 1
code sample
@app.task
def simple_task():
    return 'simple_task'


@app.task
def simple_body(args):
    return 'simple_body'


@app.task
def lower_body(args):
    return 'lower_body'


@app.task
def higher_body(args):
    return 'higher_body'


def test_chords():

    c = chord(
            group([
                chord(
                    group([
                        chord(
                            group([simple_task.s()]),
                            body=simple_body.s()
                        )
                    ]),
                    body=lower_body.s()
                )
            ]),
            body=higher_body.s()
    )
    print(c)
    c.delay()
code execution
  • Calling test_chords function - the printed chord looks fine (I re-indented it manually for clarity's sake)
>>> from tasks import test_chords
>>> test_chords()
tasks.higher_body([
    tasks.lower_body([
        tasks.simple_body([
            tasks.simple_task()
        ])
    ])
])
  • Worker output - the lower_body task was not received by the worker
[2016-07-19 12:00:24,421: INFO/MainProcess] Received task: tasks.simple_task[853a3639-1b01-4185-8eac-561f567e3cd1]
[2016-07-19 12:00:26,107: INFO/PoolWorker-8] Task tasks.simple_task[853a3639-1b01-4185-8eac-561f567e3cd1] succeeded in 0.03156297900022764s: 'simple_task'
[2016-07-19 12:00:26,108: INFO/MainProcess] Received task: tasks.simple_body[8bef991a-50b2-4daf-858a-4c81005bb6e1]
[2016-07-19 12:00:26,142: INFO/PoolWorker-3] Task tasks.simple_body[8bef991a-50b2-4daf-858a-4c81005bb6e1] succeeded in 0.0327701000005618s: 'simple_body'
[2016-07-19 12:00:26,143: INFO/MainProcess] Received task: tasks.higher_body[31cf3a3d-de1a-4ebb-ab55-ae46910d12f1]
[2016-07-19 12:00:26,153: INFO/PoolWorker-4] Task tasks.higher_body[31cf3a3d-de1a-4ebb-ab55-ae46910d12f1] succeeded in 0.007895638998888899s: 'higher_body'

Activity

  1. added this to the v4.0 milestone on Jul 19, 2016
  2. bruno-rino commented on Aug 9, 2016

    @bruno-rino

    This seems to be a rabbitmq specific bug. Your sample code works fine using redis. Related to #3330

  3. ask commented on Sep 8, 2016

    @ask
    Contributor

    Could you try this now with the most recent master?

  4. aauroy commented on Sep 9, 2016

    @aauroy
    Author

    As of commit 8e8b428, the bug is still present. Furthermore, I could also reproduce the bug when using redis as a broker, which let me think that it is not a rabbitmq specific bug.

    using redis as a broker - the lower_body body task is still not sent/received
    celery@xxxxxxx v4.0.0rc4 (0today8)
    
    Darwin-15.6.0-x86_64-i386-64bit 2016-09-09 09:25:29
    
    [config]
    .> app:         hello:0x1065d1518
    .> transport:   redis://localhost:6379/1
    .> results:     redis://localhost:6379/0
    .> concurrency: 8 (prefork)
    .> task events: OFF (enable -E to monitor tasks in this worker)
    
    [queues]
    .> celery           exchange=celery(direct) key=celery
    
    
    [tasks]
      . tasks.higher_body
      . tasks.lower_body
      . tasks.simple_body
      . tasks.simple_task
    
    [2016-09-09 09:25:29,503: INFO/MainProcess] Connected to redis://localhost:6379/1
    [2016-09-09 09:25:29,519: INFO/MainProcess] mingle: searching for neighbors
    [2016-09-09 09:25:30,550: INFO/MainProcess] mingle: all alone
    [2016-09-09 09:25:30,575: WARNING/MainProcess] celery@xxxxxxxxx ready.
    [2016-09-09 09:25:47,661: INFO/MainProcess] Received task: tasks.simple_task[8371286a-3327-44a3-9d18-ee2c15bce334]
    [2016-09-09 09:25:47,702: INFO/PoolWorker-3] Task tasks.simple_task[8371286a-3327-44a3-9d18-ee2c15bce334] succeeded in 0.03872191200002817s: 'simple_task'
    [2016-09-09 09:25:47,702: INFO/MainProcess] Received task: tasks.simple_body[7fbea240-3df0-458b-8218-2c8cc647df98]
    [2016-09-09 09:25:47,745: INFO/PoolWorker-1] Task tasks.simple_body[7fbea240-3df0-458b-8218-2c8cc647df98] succeeded in 0.04129336599999078s: 'simple_body'
    [2016-09-09 09:25:47,746: INFO/MainProcess] Received task: tasks.higher_body[a222fb42-464a-4f2d-b059-206b81d80933]
    [2016-09-09 09:25:47,756: INFO/PoolWorker-4] Task tasks.higher_body[a222fb42-464a-4f2d-b059-206b81d80933] succeeded in 0.007937469000012243s: 'higher_body'
    
    celery report output - redis as a broker
    ➜  celery -A tasks report
    
    software -> celery:4.0.0rc4 (0today8) kombu:4.0.0rc4 py:3.5.2
                billiard:3.5.0.1 redis:2.10.5
    platform -> system:Darwin arch:64bit imp:CPython
    loader   -> celery.loaders.app.AppLoader
    settings -> transport:redis results:redis://localhost:6379/0
    
    broker_url: 'redis://localhost:6379/1'
    result_backend: 'redis://localhost:6379/0'
    
    celery report output - rabbitmq as a broker
    ➜  celery -A tasks report
    
    software -> celery:4.0.0rc4 (0today8) kombu:4.0.0rc4 py:3.5.2
                billiard:3.5.0.1 py-amqp:2.1.0
    platform -> system:Darwin arch:64bit imp:CPython
    loader   -> celery.loaders.app.AppLoader
    settings -> transport:amqp results:redis://localhost:6379/0
    
    result_backend: 'redis://localhost:6379/0'
    broker_url: 'amqp://guest:********@localhost:5672//'
    
  5. bruno-rino commented on Sep 9, 2016

    @bruno-rino

    Well, I'm not sure what I tested before.

    But from my testing today, using the latest master, it seems the problem is that when using explicit chords, the choice of result_backend matters. I didn't get either redis or rpc to work.

    The following changes to your setup make it work:

    1. use 'amqp' as the result_backend. It is getting deprecated, but it works, at least fior this example!
    2. re-write your task definition using "implicit chords", i.e., just chain a task after a group. That seems to work flawlessly (which makes me happy, I find this syntax much clearer):
        c = chain(
                group([
                    chain(
                        group([
                            chain(
                                group([simple_task.s()]),
                                simple_body.s()
                            )
                        ]),
                        lower_body.s()
                    )
                ]),
                higher_body.s()
        )

    Now, for setups that don't work:

  6. ask commented on Nov 1, 2016

    @ask
    Contributor

    Something like this works well for me:

    def test_chords2():
        c = chord([
            group([simple_task.si(i=1), simple_task.si(i=2)]) | simple_body.si(i=3),
            (group([simple_task.si(i=4), simple_task.si(i=5)]) |
                chord(group(simple_task.si(i=21), simple_task.si(i=22)),
                      body=simple_body.si(i=6))),
        ], body=simple_body.si(i=7))
        c.delay()

    Note: I changed the tasks to take a integer argument, just so I could track what happens.

    These are three nested chords, but the major difference is that the groups are actual groups, since they contain more than one task.

    In your example the groups are pointless, you're defining chords that could just be a simple chain:

    simple_task.s() | simple_body.s() | lower_body.s() | higher_body.s()

    Another version that seems to work is:

    def test_chords3():
        c = group([
            group([
                group([simple_task.si(i=1)]) | simple_body.si(i=2)
            ]) | lower_body.si(i=3)
    
        ]) | higher_body.si(i=4)
        print(c)
        c.delay()
        return c

    I'm guessing this is due to how the | (OR) operator is much smarter than using the chain class, since the OR operator are able to optimize away some pointless constructs (OR operator is allowed to return a different type, while creating a chain explicitly cannot return a different type).

    We already unroll groups ORed together:

    group(A.s(), B.s()) | group([C.s(), D.s()) -> group(A.s(), B.s(), C.s(), D.s())

    We should probably also unroll chords where the group only has one member:

    something | chord(group(A.s()),  body.s()) -> something | A.s() | body.s()
  7. modified the milestones: v4.1, v4.0 on Nov 2, 2016
  8. modified the milestones: v4.0, v4.1 on Nov 2, 2016
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