Skip to content

Commit

Permalink
Get job
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsegarra committed Apr 26, 2024
1 parent ef3005e commit 66b4e62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING)

jobs = dict()
node_ids = set()
node_ids = dict()


# check all calls are valid
Expand Down Expand Up @@ -79,10 +79,10 @@ def process_workflow_job():
if job.action == "queued":
# add to memory
jobs[job.id] = job
node_ids.add(job.node_id)
node_ids[job.node_id] = job

elif job.action == "in_progress":
node_ids.discard(job.node_id)
node_ids.pop(job.node_id, None)
job_requested = jobs.get(job.id)
time_to_start = None
if not job_requested:
Expand Down Expand Up @@ -110,7 +110,7 @@ def process_workflow_job():
jobs[job.id] = job

elif job.action == "completed":
node_ids.discard(job.node_id)
node_ids.pop(job.node_id, None)
job_requested = jobs.get(job.id)
if not job_requested:
app.logger.warning(f"Job {job.id} is {job.action} but not stored!")
Expand Down Expand Up @@ -151,11 +151,11 @@ def monitor_queued_jobs():
if not node_ids:
return

jobs_data = query_nodes(list(node_ids))
jobs_data = query_nodes(node_ids.keys())
details = extract_jobs_metrics_from_data(jobs_data, node_ids)

for run in details:
job = jobs[run["job_id"]]
job = node_ids[run["job_id"]]
app.logger.info(f"Got job {job}")
statsd.histogram(
'midokura.github_runners.jobs.seconds_in_queue.histogram',
Expand Down
13 changes: 6 additions & 7 deletions src/job_processor.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
from datetime import datetime


def extract_jobs_metrics_from_data(jobs_data: dict, queued_node_ids_set: set):
def extract_jobs_metrics_from_data(jobs_data: dict, queued_node_ids: dict):
jobs_metrics = []

for job in jobs_data["nodes"]:

if job["status"] != "QUEUED":
queued_node_ids_set.discard(job["id"])
continue

started_at = datetime.strptime(job["startedAt"], "%Y-%m-%dT%H:%M:%SZ")
now = datetime.now()

context_details = {
"action": "monitor_queued",
"job_id": job["id"],
"job_run": job["checkSuite"]["workflowRun"]["runNumber"],
"job_name": job["name"],
"status": job["status"],
"started_at": job["startedAt"],
Expand All @@ -25,4 +19,9 @@ def extract_jobs_metrics_from_data(jobs_data: dict, queued_node_ids_set: set):
}

jobs_metrics.append(context_details)

if job["status"] != "QUEUED":
queued_node_ids.pop(job["id"], None)
continue

return jobs_metrics

0 comments on commit 66b4e62

Please sign in to comment.