77
88
99from const import GithubHeaders , LOGGING_CONFIG
10- from utils import parse_datetime
10+ from utils import parse_datetime , dict_to_logfmt
1111
1212dictConfig (LOGGING_CONFIG )
1313
@@ -53,13 +53,16 @@ def process_workflow_job():
5353 repository = job ["repository" ]["full_name" ]
5454 action = job ["action" ]
5555
56+ context_details = {
57+ "action" : action ,
58+ "repository" : repository ,
59+ "job_id" : job_id ,
60+ "workflow" : workflow ,
61+ }
62+
5663 if action == "queued" :
5764 # add to memory as timestamp
5865 jobs [job_id ] = int (time_start .timestamp ())
59- msg = (
60- f"action={ action } repository={ repository } job_id={ job_id } "
61- f' workflow="{ workflow } "'
62- )
6366
6467 elif action == "in_progress" :
6568 job_requested = jobs .get (job_id )
@@ -68,10 +71,7 @@ def process_workflow_job():
6871 time_to_start = 0
6972 else :
7073 time_to_start = (time_start - datetime .fromtimestamp (job_requested )).seconds
71- msg = (
72- f"action={ action } repository={ repository } job_id={ job_id } "
73- f' workflow="{ workflow } " time_to_start={ time_to_start } '
74- )
74+ context_details ["time_to_start" ] = time_to_start
7575
7676 elif action == "completed" :
7777 job_requested = jobs .get (job_id )
@@ -84,18 +84,15 @@ def process_workflow_job():
8484 ).seconds
8585 # delete from memory
8686 del jobs [job_id ]
87- msg = (
88- f"action={ action } repository={ repository } job_id={ job_id } "
89- f' workflow="{ workflow } " time_to_finish={ time_to_finish } '
90- )
87+ context_details ["time_to_finish" ] = time_to_finish
9188 else :
9289 app .logger .warning (f"Unknown action { action } , removing from memory" )
9390 if job_id in jobs :
9491 del jobs [job_id ]
95- msg = None
92+ context_details = None
9693
97- if msg :
98- app .logger .info (msg )
94+ if context_details :
95+ app .logger .info (dict_to_logfmt ( context_details ) )
9996 return True
10097
10198
0 commit comments