-
Notifications
You must be signed in to change notification settings - Fork 13
feat(worker): make upload_finisher source-of-truth for commit uploads #756
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: main
Are you sure you want to change the base?
Changes from 14 commits
2cea686
6cab9cc
95a8a79
126a0b6
6e3b939
8852b60
b75054e
4322546
b4a0fcd
c3ff0f9
6306ed5
2a0e36e
7dcdac6
6d43a16
93f3146
53bc3ab
a0cbf7e
ceb7614
c48148b
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from shared.helpers.redis import get_redis_connection | ||
|
|
||
| FINISHER_GATE_KEY_PREFIX = "upload_merger_lock" | ||
| FINISHER_GATE_TTL_SECONDS = 900 | ||
|
|
||
|
|
||
| def finisher_gate_key(repo_id: int, commit_sha: str) -> str: | ||
| return f"{FINISHER_GATE_KEY_PREFIX}_{repo_id}_{commit_sha}" | ||
|
|
||
|
|
||
| def try_acquire_finisher_gate(repo_id: int, commit_sha: str) -> bool: | ||
| return bool( | ||
| get_redis_connection().set( | ||
| finisher_gate_key(repo_id, commit_sha), | ||
| "1", | ||
| nx=True, | ||
| ex=FINISHER_GATE_TTL_SECONDS, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def refresh_finisher_gate_ttl(repo_id: int, commit_sha: str) -> None: | ||
| get_redis_connection().expire( | ||
| finisher_gate_key(repo_id, commit_sha), FINISHER_GATE_TTL_SECONDS | ||
| ) | ||
|
|
||
|
|
||
| def delete_finisher_gate(repo_id: int, commit_sha: str) -> None: | ||
| get_redis_connection().delete(finisher_gate_key(repo_id, commit_sha)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,18 @@ | |
| from database.models.core import Commit | ||
| from database.models.reports import Upload | ||
| from helpers.reports import delete_archive_setting | ||
| from services.processing.finisher_gate import ( | ||
| finisher_gate_key, | ||
| try_acquire_finisher_gate, | ||
| ) | ||
| from services.report import ProcessingError, RawReportInfo, ReportService | ||
| from services.report.parser.types import VersionOneParsedRawReport | ||
| from shared.api_archive.archive import ArchiveService | ||
| from shared.celery_config import upload_finisher_task_name | ||
| from shared.yaml import UserYaml | ||
|
|
||
| from .intermediate import save_intermediate_report | ||
| from .state import ProcessingState, should_trigger_postprocessing | ||
| from .state import ProcessingState, should_perform_merge | ||
| from .types import ProcessingResult, UploadArguments | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
@@ -43,8 +47,8 @@ def process_upload( | |
| upload = db_session.query(Upload).filter_by(id_=upload_id).first() | ||
| assert upload | ||
|
|
||
| state = ProcessingState(repo_id, commit_sha) | ||
| # this in a noop in normal cases, but relevant for task retries: | ||
| state = ProcessingState(repo_id, commit_sha, db_session=db_session) | ||
| # this is a noop in normal cases, but relevant for task retries: | ||
| state.mark_uploads_as_processing([upload_id]) | ||
thomasrockhu-codecov marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+51
to
52
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: A call is made to Suggested FixRemove the call to the non-existent Prompt for AI Agent |
||
|
|
||
| report_service = ReportService(commit_yaml) | ||
|
|
@@ -70,28 +74,29 @@ def process_upload( | |
| if processing_result.report: | ||
| save_intermediate_report(upload_id, processing_result.report) | ||
| state.mark_upload_as_processed(upload_id) | ||
| db_session.commit() | ||
|
|
||
| # Check if all uploads are now processed and trigger finisher if needed | ||
thomasrockhu-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # This handles the case where a processor task retries outside of a chord | ||
| # (e.g., from visibility timeout or task_reject_on_worker_lost) | ||
| upload_numbers = state.get_upload_numbers() | ||
| if should_trigger_postprocessing(upload_numbers): | ||
| log.info( | ||
| "All uploads processed, triggering finisher", | ||
| extra={ | ||
| "repo_id": repo_id, | ||
| "commit_sha": commit_sha, | ||
| "upload_id": upload_id, | ||
| }, | ||
| ) | ||
| celery_app.tasks[upload_finisher_task_name].apply_async( | ||
| kwargs={ | ||
| if should_perform_merge(upload_numbers): | ||
| gate_key = finisher_gate_key(repo_id, commit_sha) | ||
| if try_acquire_finisher_gate(repo_id, commit_sha): | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.info( | ||
thomasrockhu-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Enqueuing upload finisher via gate", | ||
| extra={ | ||
| "repo_id": repo_id, | ||
| "commit_sha": commit_sha, | ||
| "upload_id": upload_id, | ||
| "gate_key": gate_key, | ||
| }, | ||
| ) | ||
| finisher_kwargs = { | ||
| "repoid": repo_id, | ||
| "commitid": commit_sha, | ||
| "commit_yaml": commit_yaml.to_dict(), | ||
| } | ||
| ) | ||
|
|
||
| celery_app.tasks[upload_finisher_task_name].apply_async( | ||
| kwargs=finisher_kwargs | ||
| ) | ||
| rewrite_or_delete_upload(archive_service, commit_yaml, report_info) | ||
|
|
||
| except CeleryError: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.