Timeout-then-queue background search#372
Open
level09 wants to merge 3 commits into
Open
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# Conflicts: # enferno/settings.py
# Conflicts: # enferno/admin/views/actors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Long searches no longer hold a web worker (and its GIL) hostage. Interactive searches on the bulletin, actor, and incident list endpoints now run under a Postgres
statement_timeout(default 30s,SEARCH_TIMEOUTenv, 0 disables). When the database cancels one, the same query is re-queued to Celery, which re-runs it with a generous bound (default 10 min,BACKGROUND_SEARCH_TIME_LIMIT), stores up to 10k matching ids in Redis for 24 hours, and notifies the user with a link that replays the stored ids in the normal list view via the existingidsfilter.This is the same sync-with-async-fallback model used by Elasticsearch's async search API (
wait_for_completion_timeout) and Superset's SQL Lab (SQLLAB_TIMEOUT+ Celery).enferno/utils/background_search.py: timeout helper (SET LOCAL, so the bound dies with the transaction and can't leak through the pool), 57014 detection, Redis result store, and atimeout_fallbackdecorator that converts a canceled search into a 202{queued, token}responseenferno/tasks/background_search.py: Celery task; id-only select, completion/failure notification (newBACKGROUND_SEARCH_STATUSevent, in-app only)apply_search_timeout()call placed after activity logging (the activity commit would otherwise end the transaction and drop the bound)GET /admin/api/background-search/<token>: owner-only stored ids?bgs=<token>on the list pages loads stored ids and runs the searchTest plan
uv run pytest tests/test_background_search.py(timeout detection via realpg_sleepcancel, result store round-trip, full task run asserting stored ids + notification, endpoint 202 path)tests/test_core_entities.pyandtests/test_search_query_combination.pypass unchangedSEARCH_TIMEOUT=1, run a heavy search, confirm snackbar, notification, and results link