Skip to content

MongoDB result backend doesn't handle chords with more than one task in group #4701

Open

Description

@adriannye

I realize MongoDB is not a supported backend, but I since there is code included for it, I thought I would try to get this feature working. At least it would be good to have it report an appropriate exception instead of silently failing.

Checklist

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
  • I have verified that the issue exists against the master branch of Celery.

software -> celery:4.1.0 (latentcall) kombu:4.1.0 py:3.6.3
billiard:3.5.0.3 pymongo:3.6.1
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:mongodb results:mongodb://mypreview_celery:**@astdc-mongo01p.dimensional.com%2Castdc-mongo02p.dimensional.com%2Castdc-mongo03p.dimensional.com/mypreview_celery

CELERY_INCLUDE: ['clientsite.accounts.tasks',
'clientsite.funds.utils',
'clientsite.layout.gen',
'clientsite.notify.tasks',
'snapshot.tasks']
BROKER_URL: 'mongodb://mypreview_celery:@astdc-mongo01p..com,astdc-mongo02p..com,astdc-mongo03p..com/mypreview_celery'
CELERY_RESULT_BACKEND: 'mongodb://mypreview_celery:
@astdc-mongo01p..com%2Castdc-mongo02p..com%2Castdc-mongo03p..com/mypreview_celery'
CELERY_MONGODB_BACKEND_SETTINGS: {
'database': '********'}
CELERY_TRACK_STARTED: True
CELERY_SEND_TASK_SENT_EVENT: True
CELERY_SEND_TASK_ERROR_EMAILS: False
ADMINS:
(('IT Comms Support', '[email protected]'),)
SERVER_EMAIL: 'Webmaster [email protected]'
EMAIL_HOST: 'localhost'
EMAIL_PORT: 25

Steps to reproduce

Create a chord with a single task in the header group. Run it asynchronously and both the header task and the body task are executed in series as expected.

Add one more task to the header group of the chord, and run it asynchronously.

The tasks in the header group are executed in parallel but when they complete the callback (body) task is never executed. It's as if celery doesn't notice that the group is complete.

For example, this works:
task_id_list = [1]
batch_id = 'ASD123'
report_jobs = group(tasks.generate_snapshot.s(id) for id in task_id_list)
all_jobs = chord(report_jobs, (tasks.zip_snapshot_batch.s(batch_id=batch_id) |
tasks.notify_generation_batch_completion.s(batch_id=batch_id)))
all_jobs.delay()

But after changing the task_id_list to [1,2] the generate_shapshot tasks are executed in parallel but the zip_snapshot and notify_generation tasks are never called.

Expected behavior

The callback should be called regardless of how many tasks are in the group, when all the groups tasks are complete.

Actual behavior

The callback is called only if there is a single task in the group.

It looks like the code intends to save group results to the 'celery_groupmeta' collection in mongodb. But it doesn't actually save anything to this collection.

Comments

I suppose (not verified) that the single task chord header works because it is interpreted as a chain which doesn't require the saving of groups results.

If the maintainers think it's appropriate, I could try to fix this using the current code. Or try
a different implementation of MongoBackend subclassed from KeyValueStoreBackend, since it implements some nice features like the increment counting, which should work in mongo.

Activity

  1. auvipy commented on Jun 26, 2019

    @auvipy
    Member

    current status with celery 4.4rc2?

  2. aleksvidak commented on Jul 30, 2020

    @aleksvidak

    I can confirm this issue still exists in celery==4.4.6, has anyone found a workaround?

  3. auvipy commented on Jul 31, 2020

    @auvipy
    Member

    even in master?

  4. reopened this on Jul 31, 2020
  5. added this to the 4.4.x milestone on Jul 31, 2020
  6. aleksvidak commented on Jul 31, 2020

    @aleksvidak

    even in master?

    Yes, just tried it. If it helps, I have one worker with default concurrency (4 cores).

  7. auvipy commented on Jul 31, 2020

    @auvipy
    Member

    can you please provide a test case?

  8. modified the milestones: 4.4.x, 5.2 on Jan 3, 2021
  9. modified the milestones: 5.2, 5.3 on Oct 30, 2021
  10. nmoreaud commented on Jan 25, 2022

    @nmoreaud

    Could you add documentation about what is supported or not for each result backend type?
    Coud you add recommandations about which result backend to choose? (best support)

    There used to be some information but it have been removed: https://docs.celeryproject.org/en/3.1/getting-started/brokers/mongodb.html
    https://docs.celeryproject.org/en/v5.2.3/getting-started/introduction.html#get-started

  11. auvipy commented on Jan 25, 2022

    @auvipy
    Member

    it's was planned to be removed but should be supported now

  12. nmoreaud commented on Jan 25, 2022

    @nmoreaud

    I have a doubt, I am encountering infinite loops with basic example chord (see last comment of this ticket:
    #3709)

  13. modified the milestones: 5.3, Future on Feb 19, 2023
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions