Skip to content

Commit

Permalink
If checkSuit is completed, we should stop tracking the queued job
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsegarra committed Dec 5, 2024
1 parent 94c9487 commit 3ac34a2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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.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",
"checkSuit": {"status": "IN_PROGRESS"},
"startedAt": "2024-04-29T12:43:16Z",
"completedAt": None,
},
{
"id": "workflow_id_in_progress",
"status": "IN_PROGRESS",
"checkSuit": {"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",
"checkSuit": {"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()

0 comments on commit 3ac34a2

Please sign in to comment.