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

If checkSuite is completed, we should stop tracking the queued job #45

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-docstring-first
Expand All @@ -11,11 +11,6 @@ repos:
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- repo: https://github.com/myint/docformatter
rev: v1.7.5
hooks:
- id: docformatter
args: [--in-place]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
Expand Down
5 changes: 4 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def monitor_jobs():

for job_data in jobs_data["nodes"]:
job = job_handler.queued.get(job_data["id"])
if job_data["status"] != "QUEUED":
if (
job_data.get("checkSuite", {}).get("status") == "COMPLETED"
or job_data["status"] != "QUEUED"
):
job = job_handler.queued.pop(job_data["id"], None)
app.logger.info(
f"Job {job_data['id']} is no longer queued {job_data['status']}"
Expand Down
1 change: 1 addition & 0 deletions src/query_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def query_jobs(node_id_list: List[str]):
name
}
checkSuite {
status
workflowRun {
event
runNumber
Expand Down
30 changes: 30 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ def test_monitor_jobs(
{
"id": "workflow_id_queued",
"status": "QUEUED",
"checkSuite": {"status": "IN_PROGRESS"},
"startedAt": "2024-04-29T12:43:16Z",
"completedAt": None,
},
{
"id": "workflow_id_in_progress",
"status": "IN_PROGRESS",
"checkSuite": {"status": "IN_PROGRESS"},
"startedAt": "2024-04-29T12:43:32Z",
"completedAt": None,
},
Expand All @@ -86,3 +88,31 @@ def test_monitor_jobs(
assert in_progress_job.status == "in_progress"
assert in_progress_job.in_progress_at is not None
send_queued_metric_mock.assert_called()


@patch("jobs.Job.send_queued_metric")
@patch("app.query_jobs")
def test_monitor_jobs_completed_suit(
query_jobs_mock, send_queued_metric_mock, queued_job
):
app.job_handler = JobEventsHandler()
app.job_handler.queued = {
"workflow_id_queued": queued_job,
}

query_jobs_mock.return_value = {
"nodes": [
{
"id": "workflow_id_queued",
"status": "QUEUED",
"checkSuite": {"status": "COMPLETED"},
"startedAt": "2024-04-29T12:43:16Z",
"completedAt": None,
}
]
}

monitor_jobs()

assert "workflow_id_queued" not in app.job_handler.queued
send_queued_metric_mock.assert_called()
Loading