17
17
import logging
18
18
from datetime import datetime
19
19
20
+ from github .WorkflowRun import WorkflowRun , WorkflowRunJob
20
21
from prometheus_client import Counter , Gauge , Histogram , Info
21
22
from .estimate import get_server_price
22
23
from .constants import standby_server_name_prefix , recycle_server_name_prefix
@@ -656,7 +657,7 @@ def update_runners(
656
657
).set (count )
657
658
658
659
659
- def update_jobs (workflow_runs ):
660
+ def update_jobs (run_jobs : list [( WorkflowRun , WorkflowRunJob )] ):
660
661
"""Update all job-related metrics."""
661
662
queued_count = 0
662
663
running_count = 0
@@ -670,66 +671,66 @@ def update_jobs(workflow_runs):
670
671
RUNNING_JOB_LABELS ._metrics .clear ()
671
672
RUNNING_JOB_TIME ._metrics .clear ()
672
673
673
- for run in workflow_runs :
674
- for job in run .jobs ():
675
- # Normalize job status
676
- status = normalize_status (job )
674
+ for run , job in run_jobs :
675
+
676
+ # Normalize job status
677
+ status = normalize_status (job )
678
+
679
+ job_info = {
680
+ "name" : job .name ,
681
+ "workflow_name" : run .name ,
682
+ "repository" : run .repository .full_name ,
683
+ "status" : status ,
684
+ "queued_at" : job .raw_data .get ("started_at" , "" ),
685
+ "run_attempt" : str (run .run_attempt ),
686
+ "run_number" : str (run .run_number ),
687
+ "head_branch" : run .head_branch or "" ,
688
+ "head_sha" : run .head_sha or "" ,
689
+ }
690
+
691
+ if status == "queued" :
692
+ queued_count += 1
693
+ # Track detailed job info
694
+ QUEUED_JOB_INFO .labels (job_id = str (job .id ), run_id = str (run .id )).info (
695
+ job_info
696
+ )
677
697
678
- job_info = {
679
- "name" : job .name ,
680
- "workflow_name" : run .name ,
681
- "repository" : run .repository .full_name ,
682
- "status" : status ,
683
- "queued_at" : job .raw_data .get ("started_at" , "" ),
684
- "run_attempt" : str (run .run_attempt ),
685
- "run_number" : str (run .run_number ),
686
- "head_branch" : run .head_branch or "" ,
687
- "head_sha" : run .head_sha or "" ,
688
- }
698
+ # Track job labels
699
+ for label in job .raw_data .get ("labels" , []):
700
+ QUEUED_JOB_LABELS .labels (
701
+ job_id = str (job .id ), run_id = str (run .id ), label = label .lower ()
702
+ ).set (1 )
689
703
690
- if status == "queued" :
691
- queued_count += 1
692
- # Track detailed job info
693
- QUEUED_JOB_INFO .labels (job_id = str (job .id ), run_id = str (run .id )).info (
694
- job_info
704
+ # Track job wait time
705
+ started_at = job .raw_data .get ("started_at" )
706
+ if started_at :
707
+ started_at = dateutil .parser .parse (started_at )
708
+ wait_time = current_time - started_at .timestamp ()
709
+ QUEUED_JOB_WAIT_TIME .labels (job_id = str (job .id ), run_id = str (run .id )).set (
710
+ wait_time
695
711
)
696
712
697
- # Track job labels
698
- for label in job .raw_data .get ("labels" , []):
699
- QUEUED_JOB_LABELS .labels (
700
- job_id = str (job .id ), run_id = str (run .id ), label = label .lower ()
701
- ).set (1 )
702
-
703
- # Track job wait time
704
- started_at = job .raw_data .get ("started_at" )
705
- if started_at :
706
- started_at = dateutil .parser .parse (started_at )
707
- wait_time = current_time - started_at .timestamp ()
708
- QUEUED_JOB_WAIT_TIME .labels (
709
- job_id = str (job .id ), run_id = str (run .id )
710
- ).set (wait_time )
711
-
712
- elif status == "in_progress" :
713
- running_count += 1
714
- # Track detailed job info
715
- RUNNING_JOB_INFO .labels (job_id = str (job .id ), run_id = str (run .id )).info (
716
- job_info
717
- )
713
+ elif status == "in_progress" :
714
+ running_count += 1
715
+ # Track detailed job info
716
+ RUNNING_JOB_INFO .labels (job_id = str (job .id ), run_id = str (run .id )).info (
717
+ job_info
718
+ )
718
719
719
- # Track job labels
720
- for label in job .raw_data .get ("labels" , []):
721
- RUNNING_JOB_LABELS .labels (
722
- job_id = str (job .id ), run_id = str (run .id ), label = label .lower ()
723
- ).set (1 )
720
+ # Track job labels
721
+ for label in job .raw_data .get ("labels" , []):
722
+ RUNNING_JOB_LABELS .labels (
723
+ job_id = str (job .id ), run_id = str (run .id ), label = label .lower ()
724
+ ).set (1 )
724
725
725
- # Track job run time
726
- started_at = job .raw_data .get ("started_at" )
727
- if started_at :
728
- started_at = dateutil .parser .parse (started_at )
729
- run_time = current_time - started_at .timestamp ()
730
- RUNNING_JOB_TIME .labels (job_id = str (job .id ), run_id = str (run .id )).set (
731
- run_time
732
- )
726
+ # Track job run time
727
+ started_at = job .raw_data .get ("started_at" )
728
+ if started_at :
729
+ started_at = dateutil .parser .parse (started_at )
730
+ run_time = current_time - started_at .timestamp ()
731
+ RUNNING_JOB_TIME .labels (job_id = str (job .id ), run_id = str (run .id )).set (
732
+ run_time
733
+ )
733
734
734
735
QUEUED_JOBS .set (queued_count )
735
736
RUNNING_JOBS .set (running_count )
0 commit comments