From 84458052f92830de1bb209130af6cfa62d23bbf8 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Mon, 6 Mar 2023 13:57:59 +0000 Subject: [PATCH] Fix #4 Fixes an issue where a job had a date of the year 0001, meaning the values were negative when added up. This was from jobs which were queued or still running. Thanks to folks on the issue for their input Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 5c8702f..e3542b5 100644 --- a/main.go +++ b/main.go @@ -181,10 +181,14 @@ func main() { log.Printf("%d jobs for workflow run: %d", len(workflowJobs), run.GetID()) for _, job := range workflowJobs { - dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time) - allUsage += dur - log.Printf("Job: %d [%s - %s] (%s): %s", - job.GetID(), job.GetStartedAt().Format("2006-01-02 15:04:05"), job.GetCompletedAt().Format("2006-01-02 15:04:05"), humanDuration(dur), job.GetConclusion()) + if !job.GetCompletedAt().IsZero() { + dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time) + allUsage += dur + log.Printf("Job: %d [%s - %s] (%s): %s", + job.GetID(), job.GetStartedAt().Format("2006-01-02 15:04:05"), + job.GetCompletedAt().Format("2006-01-02 15:04:05"), + humanDuration(dur), job.GetConclusion()) + } } } }