Skip to content

Commit

Permalink
fix(status): correctly display duration of stopped workflows (reanahu…
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-steduto committed Jan 29, 2024
1 parent d70f5e0 commit 233c616
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 10 deletions.
3 changes: 3 additions & 0 deletions client/operations/get_workflow_status_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/operations/get_workflows_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 145 additions & 4 deletions client/operations/launch_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func displayListPayload(
value, err = workflows.GetDuration(
workflow.Progress.RunStartedAt,
workflow.Progress.RunFinishedAt,
workflow.Progress.RunStoppedAt,
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func displayStatusPayload(
value, err = workflows.GetDuration(
p.Progress.RunStartedAt,
p.Progress.RunFinishedAt,
p.Progress.RunStoppedAt,
)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion pkg/workflows/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetNameAndRunNumber(workflowName string) (string, string) {
}

// GetDuration calculates and returns the duration the workflow, based on the given timestamps.
func GetDuration(runStartedAt, runFinishedAt *string) (any, error) {
func GetDuration(runStartedAt, runFinishedAt *string, runStoppedAt *string) (any, error) {
if runStartedAt == nil {
return nil, nil
}
Expand All @@ -43,6 +43,11 @@ func GetDuration(runStartedAt, runFinishedAt *string) (any, error) {
if err != nil {
return nil, err
}
} else if runStoppedAt != nil {
endTime, err = datautils.FromIsoToTimestamp(*runStoppedAt)
if err != nil {
return nil, err
}
} else {
endTime = time.Now()
}
Expand Down
27 changes: 22 additions & 5 deletions pkg/workflows/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,33 @@ func TestGetDuration(t *testing.T) {
tests := map[string]struct {
runStartedAt *string
runFinishedAt *string
runStoppedAt *string
want any
wantError bool
}{
"finished instantly": {runStartedAt: &curTime, runFinishedAt: &curTime, want: 0.0},
"finished in 1 second": {runStartedAt: &curTime, runFinishedAt: &future, want: 1.0},
"finished before start": {runStartedAt: &curTime, runFinishedAt: &past, want: -1.0},
"nil arguments": {runStartedAt: nil, runFinishedAt: nil, want: nil},
"nil start": {runStartedAt: nil, runFinishedAt: &curTime, want: nil},
"nil finish": {runStartedAt: &curTime, runFinishedAt: nil},
"bad start format": {runStartedAt: &badFormat, wantError: true},
"stopped in 1 second": {
runStartedAt: &curTime,
runFinishedAt: nil,
runStoppedAt: &future,
want: 1.0,
},
"nil arguments": {
runStartedAt: nil,
runFinishedAt: nil,
runStoppedAt: nil,
want: nil,
},
"nil start": {runStartedAt: nil, runFinishedAt: &curTime, want: nil},
"nil finish": {runStartedAt: &curTime, runFinishedAt: nil},
"bad start format": {runStartedAt: &badFormat, wantError: true},
"bad stop format": {
runStartedAt: &curTime,
runStoppedAt: &badFormat,
wantError: true,
},
"bad finish format": {
runStartedAt: &curTime,
runFinishedAt: &badFormat,
Expand All @@ -63,7 +80,7 @@ func TestGetDuration(t *testing.T) {
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
got, err := GetDuration(test.runStartedAt, test.runFinishedAt)
got, err := GetDuration(test.runStartedAt, test.runFinishedAt, test.runStoppedAt)
if test.wantError {
if err == nil {
t.Errorf("Expected error, got nil")
Expand Down

0 comments on commit 233c616

Please sign in to comment.