-
Notifications
You must be signed in to change notification settings - Fork 12
feat(worker): pass db_session to ProcessingState in processor #744
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
base: tomhu/processing-state-db-path
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,12 +128,10 @@ def get_upload_numbers(self): | |
| return UploadNumbers(processing, processed) | ||
|
|
||
| def mark_uploads_as_processing(self, upload_ids: list[int]): | ||
| if not upload_ids or self._db_session: | ||
| if not upload_ids: | ||
| return | ||
|
Comment on lines
130
to
132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Removing the Suggested FixRestore the Prompt for AI Agent
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing behavior identical to main branch. mark_uploads_as_processing always wrote to Redis on main (no db_session guard existed). This PR restores that same behavior for dual-write. Not a new regression. |
||
| key = self._redis_key("processing") | ||
| self._redis.sadd(key, *upload_ids) | ||
| # Set TTL to match intermediate report expiration (24 hours) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # This ensures state keys don't accumulate indefinitely | ||
| self._redis.expire(key, PROCESSING_STATE_TTL) | ||
|
|
||
| def clear_in_progress_uploads(self, upload_ids: list[int]): | ||
|
|
@@ -159,13 +157,10 @@ def clear_in_progress_uploads(self, upload_ids: list[int]): | |
| ) | ||
| if updated > 0: | ||
| CLEARED_UPLOADS.inc(updated) | ||
| self._redis.srem(self._redis_key("processing"), *upload_ids) | ||
| return | ||
| removed_uploads = self._redis.srem(self._redis_key("processing"), *upload_ids) | ||
| if removed_uploads > 0: | ||
| # the normal flow would move the uploads from the "processing" set | ||
| # to the "processed" set via `mark_upload_as_processed`. | ||
| # this function here is only called in the error case and we don't expect | ||
| # this to be triggered often, if at all. | ||
| CLEARED_UPLOADS.inc(removed_uploads) | ||
|
|
||
| def mark_upload_as_processed(self, upload_id: int): | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -176,21 +171,14 @@ def mark_upload_as_processed(self, upload_id: int): | |
| # Don't set upload.state here -- the finisher's idempotency check | ||
| # uses state="processed" to detect already-merged uploads. | ||
| # The state string is set by update_uploads() after merging. | ||
| return | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| processing_key = self._redis_key("processing") | ||
| processed_key = self._redis_key("processed") | ||
|
|
||
| res = self._redis.smove(processing_key, processed_key, upload_id) | ||
| if not res: | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # this can happen when `upload_id` was never in the source set, | ||
| # which probably is the case during initial deployment as | ||
| # the code adding this to the initial set was not deployed yet | ||
| # TODO: make sure to remove this code after a grace period | ||
| self._redis.sadd(processed_key, upload_id) | ||
|
|
||
| # Set TTL on processed key to match intermediate report expiration | ||
| # This ensures uploads marked as processed have a bounded lifetime | ||
| self._redis.expire(processed_key, PROCESSING_STATE_TTL) | ||
|
|
||
| def mark_uploads_as_merged(self, upload_ids: list[int]): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.