Skip to content

Commit 8445805

Browse files
committed
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) <[email protected]>
1 parent 847823c commit 8445805

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ func main() {
181181
log.Printf("%d jobs for workflow run: %d", len(workflowJobs), run.GetID())
182182
for _, job := range workflowJobs {
183183

184-
dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time)
185-
allUsage += dur
186-
log.Printf("Job: %d [%s - %s] (%s): %s",
187-
job.GetID(), job.GetStartedAt().Format("2006-01-02 15:04:05"), job.GetCompletedAt().Format("2006-01-02 15:04:05"), humanDuration(dur), job.GetConclusion())
184+
if !job.GetCompletedAt().IsZero() {
185+
dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time)
186+
allUsage += dur
187+
log.Printf("Job: %d [%s - %s] (%s): %s",
188+
job.GetID(), job.GetStartedAt().Format("2006-01-02 15:04:05"),
189+
job.GetCompletedAt().Format("2006-01-02 15:04:05"),
190+
humanDuration(dur), job.GetConclusion())
191+
}
188192
}
189193
}
190194
}

0 commit comments

Comments
 (0)