From ce200e6a4a086f20ba64b07d02e3cf67ca877599 Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Tue, 25 Feb 2025 23:04:42 -0300 Subject: [PATCH] bin/ci: crnm: Fix job duration calculation The former version was problematic because: - time.perf_counter() returns seconds relative to an arbitrary point in time (monotonic clock) - time.mktime() converts to epoch time (seconds since 1970) Signed-off-by: Guilherme Gallo Reviewed-by: Sergi Blanch Torne Part-of: --- bin/ci/ci_run_n_monitor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/ci/ci_run_n_monitor.py b/bin/ci/ci_run_n_monitor.py index 28fb19088b9..dddb7e20f7c 100755 --- a/bin/ci/ci_run_n_monitor.py +++ b/bin/ci/ci_run_n_monitor.py @@ -100,7 +100,10 @@ def job_duration(job: gitlab.v4.objects.ProjectPipelineJob) -> float: if job.duration: return job.duration elif job.started_at: - return time.perf_counter() - time.mktime(job.started_at.timetuple()) + # Convert both times to UTC timestamps for consistent comparison + current_time = time.time() + start_time = job.started_at.timestamp() + return current_time - start_time return 0.0