1+ from typing import Dict
12import metrics
23
34from datetime import datetime
@@ -16,6 +17,8 @@ def __init__(self, github_job: GithubJob) -> None:
1617 self ._update_attributes (github_job )
1718
1819 self .node_id = self .github_job .node_id
20+ self .labels = "-" .join (sorted (self .github_job .labels ))
21+ self .final_queued_time_updated = False
1922
2023 @property
2124 def seconds_in_queue (self ):
@@ -27,7 +30,7 @@ def seconds_in_queue(self):
2730
2831 def _update_attributes (self , github_job : GithubJob ):
2932 self .github_job : GithubJob = github_job
30- self .status = github_job .action
33+ self .status = self . github_job .action
3134
3235 if self .github_job .action == "queued" :
3336 self .queued_at = self .github_job .time_start
@@ -42,11 +45,22 @@ def _update_attributes(self, github_job: GithubJob):
4245 def update (self , github_job : GithubJob ):
4346 self ._update_attributes (github_job )
4447
48+ def send_queued_metric (self ):
49+ metrics .send_queued_job (
50+ seconds_in_queue = self .seconds_in_queue ,
51+ job_name = self .github_job .job_name ,
52+ status = self .status ,
53+ repository = self .github_job .repository ,
54+ runner_group_name = self .github_job .runner_group_name ,
55+ public = self .github_job .runner_public ,
56+ buildjet = self .github_job .runner_buildjet ,
57+ )
58+
4559
4660class JobEventsHandler :
4761 def __init__ (self ) -> None :
48- self .queued = dict ()
49- self .in_progress = dict ()
62+ self .queued : Dict [ str , Job ] = dict ()
63+ self .in_progress : Dict [ str , Job ] = dict ()
5064
5165 def process_event (self , event : dict ):
5266 status = event ["action" ]
@@ -64,7 +78,7 @@ def process_event(self, event: dict):
6478 pass
6579
6680 def _get_event_job_id (self , event : dict ):
67- return event ["workflow_job" ]["id " ]
81+ return event ["workflow_job" ]["node_id " ]
6882
6983 def _create_job (self , githubJob : GithubJob ) -> Job :
7084 return Job (github_job = githubJob )
@@ -81,14 +95,10 @@ def _process_in_progress_event(self, event: dict):
8195 job = self ._create_job (GithubJob (event ))
8296 else :
8397 job .update (GithubJob (event ))
84- metrics .send_queued_job (
85- seconds_in_queue = job .seconds_in_queue ,
86- job_name = job .github_job .job_name ,
87- repository = job .github_job .repository ,
88- runner = job .github_job .runner_name ,
89- run_id = job .github_job .run_id ,
90- public = job .github_job .runner_public ,
91- )
98+ # This is a fallover in case the job was not processed during the tracking time.
99+ if not job .final_queued_time_updated :
100+ job .final_queued_time_updated = True
101+ job .send_queued_metric ()
92102
93103 self .in_progress [job_id ] = job
94104
0 commit comments