Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exports): tasks stuck in processing TASK-1243 #5436

Merged
merged 11 commits into from
Jan 28, 2025

Conversation

rgraber
Copy link
Contributor

@rgraber rgraber commented Jan 21, 2025

🗒️ Checklist

  1. run linter locally
  2. update all related docs (API, README, inline, etc.), if any
  3. draft PR with a title <type>(<scope>)<!>: <title> TASK-1234
  4. tag PR: at least frontend or backend unless it's global
  5. fill in the template below and delete template comments
  6. review thyself: read the diff and repro the preview as written
  7. open PR & confirm that CI passes
  8. request reviewers, if needed
  9. delete this section before merging

📣 Summary

Fixes occasional problem where tasks end up showing as 'Processing' forever.

💭 Notes

Tasks were failing when the celery task started too quickly and tried to fetch the task before it had actually hit the database. This PR implements 2 guards against this:

  1. Call the tasks from within an on_commit block to ensure they only start after the task object has made it to the database
  2. Automatically catch ObjectDoesNotExist exceptions and retry the task a hardcoded number of times. task.retry takes care of putting some time in between retries

👀 Preview steps

This bug tends to only appear in low traffic when the celery queue is empty. Make sure CELERY_TASK_ALWAYS_EAGER is false.

  1. ℹ️ have an account and a project
  2. Export the project submissions
  3. 🔴 [on main] The job will show as 'Processing' indefinitely. In the worker logs, you'll see kpi.models.import_export_task.SubmissionExportTask.DoesNotExist: SubmissionExportTask matching query does not exist
  4. 🟢 [on PR] The job will only show as 'Processing' for a few seconds and then will complete.

@rgraber rgraber marked this pull request as ready for review January 22, 2025 13:48
@rgraber rgraber removed the request for review from jnm January 22, 2025 13:48
kpi/tasks.py Outdated
@@ -14,26 +15,36 @@
from kpi.models.asset import Asset
from kpi.models.import_export_task import ImportTask, SubmissionExportTask

SLEEP_TIME = 2
Copy link
Contributor

Choose a reason for hiding this comment

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

is this used anywhere?

Copy link
Contributor

@noliveleger noliveleger left a comment

Choose a reason for hiding this comment

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

LGTM. I left some tiny comments which are not blockers to merge this PR.
It would be great to address them, though ;-)

kpi/tasks.py Outdated
@@ -14,26 +15,36 @@
from kpi.models.asset import Asset
from kpi.models.import_export_task import ImportTask, SubmissionExportTask

SLEEP_TIME = 2
RETRIES = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, I would add this to django settings instead having the constant in the file.

@rgraber rgraber merged commit aa5a20c into main Jan 28, 2025
4 checks passed
@rgraber rgraber deleted the rsgraber/TASK-1243-missing-tasks branch January 28, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants