Skip to content

Conversation

@feanil
Copy link
Contributor

@feanil feanil commented Oct 29, 2020

Update the celery startup code to more closely match the docs. We believe some of these imports are causeing circulare
dependencies that are causing race conditions in task discovery. Since all django apps should be loaded using the
django fixup in celery 4, we shouldn't need these other overrides.

https://github.com/celery/celery/blob/v4.4.7/celery/fixups/django.py
https://docs.celeryproject.org/en/v4.4.7/django/first-steps-with-django.html#using-celery-with-django

Copy link
Contributor

@jmbowman jmbowman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one suggestion for further cleanup, which can probably wait until after we determine if this even works.

Update the celery startup code to more closely match the docs.  We believe some of these imports are causeing circulare
dependencies that are causing race conditions in task discovery.  Since all django apps should be loaded using the
django fixup in celery 4, we shouldn't need these other overrides.

https://github.com/celery/celery/blob/v4.4.7/celery/fixups/django.py
https://docs.celeryproject.org/en/v4.4.7/django/first-steps-with-django.html#using-celery-with-django
@feanil feanil force-pushed the feanil/update_celery_config branch from e77cfb5 to c21c172 Compare October 29, 2020 14:26
@feanil
Copy link
Contributor Author

feanil commented Oct 29, 2020

Removed the config setting entirely as suggested.

import os

from celery import Celery
from django.conf import settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on the actual line, but probably change the default value for DJANGO_SETTINGS_MODULE in here too?

@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@feanil feanil merged commit 2175d00 into master Oct 29, 2020
@feanil feanil deleted the feanil/update_celery_config branch October 29, 2020 14:52
@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR may have caused e2e tests to fail on Stage. If you're a member of the edX org, please visit #e2e-troubleshooting on Slack to help diagnose the cause of these failures. Otherwise, it is the reviewer's responsibility. E2E tests have failed. https://gocd.tools.edx.org/go/tab/pipeline/history/deploy_to_stage

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR may have caused e2e tests to fail on Stage. If you're a member of the edX org, please visit #e2e-troubleshooting on Slack to help diagnose the cause of these failures. Otherwise, it is the reviewer's responsibility. E2E tests have failed. https://gocd.tools.edx.org/go/tab/pipeline/history/deploy_to_stage

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@pomegranited
Copy link
Contributor

pomegranited commented Nov 28, 2020

Hi @feanil -- I'm running latest master on one of my sandboxes, but it's throwing UnregisteredTaskException for all the instructor_task.tasks and also openedx.core.djangoapps.heartbeat.tasks.sample_task, which we use for extended heartbeat checks.

Is there something I need to do to ensure these tasks are auto-discovered by celery?

CC @jmbowman @ormsbee

@feanil
Copy link
Contributor Author

feanil commented Nov 30, 2020

@pomegranited edX is actively still working on more things in this space, right now we're forking Celery to dig into what's going on here and to add better logging. The current theory is that import failures during Celery's autodiscovery are being swallowed by celery. We'll hopefully know more in the next week or two.

@pomegranited
Copy link
Contributor

# Celery's task autodiscovery won't find tasks nested in a tasks package.
# Tasks are only registered when the module they are defined in is imported.
CELERY_IMPORTS = (
'poll.tasks',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @feanil , edX has gotten reports that XBlock-poll's reporting features are no longer working (TNL-8370), and I think it was caused by this change (but went unnoticed for months?).

The issue is that the poll XBlock is not a django app, so its tasks.py won't get auto-discovered by celery. If so, is it OK if I fix it with a PR here to reinstate CELERY_IMPORTS = ('poll.tasks', ), or is there some other way I should be doing that now?

Previous PR: https://github.com/edx/edx-platform/pull/23700

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Braden, that seems like a fine fix, the other option would be to make the polls code into a django app? Which I would prefer but either is acceptable.

edx-community-bot added a commit that referenced this pull request Nov 1, 2021
…feature is not working [TNL-8370] [MNG-2273] [BB-4877]

## Description

This is a backport of https://github.com/edx/edx-platform/pull/28019 to the Lilac master branch, as [requested](https://github.com/edx/edx-platform/pull/28019#issuecomment-952413371) by @alfredchavez.

Summary:

> xblock-poll's celery task was broken, then fixed in #23700, then broken again by #25479. This fixes it again.


## Supporting information

See original PR.

## Testing instructions

See original PR.

## Deadline

None

## Other information

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants