Skip to content

Conversation

@ozer550
Copy link
Member

@ozer550 ozer550 commented Aug 29, 2023

Summary

Description of the change(s) you made

  • Added CustomTaskMetadata model to track metadata related to celery TaskResult objects.
  • Decouple the relationship between Celery's TaskResult Object and our custom metadata like signature, user_id, channel_id, and progress.
  • Create migrations to drop those fields from Celery's TaskResult object and migrate them to CustomTaskMetadata.
  • Refactor tests according to new changes.

Manual verification steps performed

  1. Ran all the tests.

Does this introduce any tech-debt items?

The only thing that comes to mind is find_incomplete_ids function being executed before the celery TaskObject is saved to the backend asynchronously. This edge case is very difficult to happen relatively as there should surely be some latency due to request, which would ensure the saving of the celery TaskObject in the backend safely. Just to give out some figures the test test_revoke_task when not having a delay between enqueuing and revoking the same tasks creates the above-mentioned issue but if we add a delay of just 0.5 seconds this edge case is not caused.

References

closes #4222

Comments

  • The existing tests fairly cover almost all the necessary cases but If there are any more that seem to be necessary to add, would love to add them!

Contributor's Checklist

PR process:

  • If this is an important user-facing change, PR or related issue the CHANGELOG label been added to this PR. Note: items with this label will be added to the CHANGELOG at a later time
  • If this includes an internal dependency change, a link to the diff is provided
  • The docs label has been added if this introduces a change that needs to be updated in the user docs?
  • If any Python requirements have changed, the updated requirements.txt files also included in this PR
  • Opportunities for using Google Analytics here are noted
  • Migrations are safe for a large db

Studio-specifc:

  • All user-facing strings are translated properly
  • The notranslate class been added to elements that shouldn't be translated by Google Chrome's automatic translation feature (e.g. icons, user-generated text)
  • All UI components are LTR and RTL compliant
  • Views are organized into pages, components, and layouts directories as described in the docs
  • Users' storage used is recalculated properly on any changes to main tree files
  • If there new ways this uses user data that needs to be factored into our Privacy Policy, it has been noted.

Testing:

  • Code is clean and well-commented
  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Any new interactions have been added to the QA Sheet
  • Critical and brittle code paths are covered by unit tests

Reviewer's Checklist

This section is for reviewers to fill out.

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

WIP

@ozer550 ozer550 closed this Aug 31, 2023
@ozer550 ozer550 reopened this Aug 31, 2023
@ozer550 ozer550 force-pushed the fix_celery_race_condition branch from b77dd03 to 224a05c Compare August 31, 2023 10:39
@ozer550 ozer550 changed the title add new model for taskrefernece and use celery get method Add new model for TaskReference and refactor celery code Aug 31, 2023

super_as_dict = TaskResult.as_dict

def as_dict(self):
Copy link
Member

@bjester bjester Aug 31, 2023

Choose a reason for hiding this comment

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

Could be worth checking if our own code calls this, as I overrode on TaskResult to add in the additional fields.

Copy link
Member

Choose a reason for hiding this comment

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

Edited my previous comment: missing the word 'code'. @ozer550 did you check to see if this was used at all? This was used internally to django-celery-results, and overriding it allowed us to add our custom fields to the dict.

@ozer550 ozer550 changed the title Add new model for TaskReference and refactor celery code Resolve Celery TaskObject Race Condition Sep 21, 2023
@ozer550 ozer550 marked this pull request as ready for review September 21, 2023 11:12
@ozer550 ozer550 requested review from bjester and rtibbles September 21, 2023 11:13
Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

Some important notes on the CeleryAsyncResult properties (if they're actually being used still)

@bjester bjester merged commit aef05d0 into learningequality:unstable Oct 30, 2023
@akolson akolson mentioned this pull request Aug 13, 2024
@akolson akolson mentioned this pull request Oct 1, 2024
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.

Unhandled error causing infrequent 500s from the sync endpoint

2 participants