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

Improve title resolution make it a background process #1214

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

Kirandawadi
Copy link
Collaborator

Features Added

  • Moved title pattern resolution to Celery tasks for non-blocking operation
  • Added /api/title-patterns/<pattern_id>/status/ endpoint to monitor resolution progress
  • Implemented 5-minute polling mechanism to check resolution status every 2 seconds
  • Added real-time status notifications showing progress and completion of title resolutions

@Kirandawadi Kirandawadi linked an issue Feb 3, 2025 that may be closed by this pull request
@Kirandawadi
Copy link
Collaborator Author

Demo

  • Background resolution of titles
  • Can schedule resolution for multiple title patterns at once
Background_Title_Resolution.mov

@CarsonDavis
Copy link
Collaborator

take a look at this:

    # if you want call apply by itsef apply()
    # but if want to call it async, use apply_async()

    def apply_async(self):
        return self.apply.delay(self.id, *args, **kwargs)

    @shared_task(bind=True)
    def apply(self) -> None:

@Kirandawadi
Copy link
Collaborator Author

Tests failing

  • Currently, the title resolution task is running as expected when ran from the COSMOS but tests are failing.
  • Here's how apply() method is modified.
    def apply(self) -> None:

        # Inserting here to avoid circular import issue
        from ..tasks import process_title_resolutions

        def queue_task():
            process_title_resolutions.delay(self.id)

        # Queue the background task only after the transaction commits (i.e, after apply() method)
        transaction.on_commit(queue_task)
  • During tests, my guess is that the celery workers are not working properly and handling the background tasks as they should.

Methods Tried

  • Set CELERY_ALWAYS_EAGER = True and CELERY_TASK_ALWAYS_EAGER = True on config/test.py to make async workflow to synchronous.
  • Inherit TransactionTestCase for TestDeltaTitlePattern because we are dealing with transaction-related tests.
@pytest.mark.django_db(transaction=True)
class TestDeltaTitlePattern(TransactionTestCase):
  • Marking test functions with decorators (transaction=True)
    @pytest.mark.django_db(transaction=True)
    def test_apply_generates_delta_url_if_title_differs(self):
  • This method is working but it would be troublesome to write this everytime just to apply the pattern
        # Call the `apply()` method and capture/execute `on_commit` callbacks
        with self.captureOnCommitCallbacks(execute=True):  # Ensure `on_commit` callbacks are executed
             pattern.apply()

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.

Improve title resolution; make it a background process
2 participants