Skip to content

Commit

Permalink
Fix #4
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexellis committed Mar 6, 2023
1 parent 847823c commit 8445805
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
}
Expand Down

0 comments on commit 8445805

Please sign in to comment.