Skip to content

Commit

Permalink
Set 'ended_at' on crashed tasks too.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Nov 14, 2023
1 parent 61512b8 commit a6daf6c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 85 deletions.
8 changes: 4 additions & 4 deletions client/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ var watchCmd = &cobra.Command{

if t.StartedAt != nil {
var taskRunningFor time.Duration
if t.CompletedAt != nil {
taskRunningFor = t.CompletedAt.AsTime().Sub(t.StartedAt.AsTime()).Truncate(time.Second)
if t.EndedAt != nil {
taskRunningFor = t.EndedAt.AsTime().Sub(t.StartedAt.AsTime()).Truncate(time.Minute)
} else {
taskRunningFor = time.Since(t.StartedAt.AsTime()).Truncate(time.Second)
taskRunningFor = time.Since(t.StartedAt.AsTime()).Truncate(time.Minute)
}
if taskRunningFor >= someTime {
label += fmt.Sprintf(" (%s%s)", emoji(lo.Ternary(taskRunningFor >= aLongTime, "🧟", "🐢")), taskRunningFor)
}
} else {
taskQueuedFor := time.Since(msg.ScheduledAt.AsTime()).Truncate(time.Second)
taskQueuedFor := time.Since(msg.ScheduledAt.AsTime()).Truncate(time.Minute)
if taskQueuedFor >= aVeryLongTime {
label += fmt.Sprintf(" (%s%s)", emoji("😴"), taskQueuedFor)
}
Expand Down
151 changes: 75 additions & 76 deletions proto/alfred.pb.go

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

2 changes: 1 addition & 1 deletion proto/alfred.proto
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ message TaskStatus {
Status status = 2;
optional int32 exit_code = 3;
google.protobuf.Timestamp started_at = 4;
optional google.protobuf.Timestamp completed_at = 5;
optional google.protobuf.Timestamp ended_at = 5;

enum Status {
UNKNOWN = 0;
Expand Down
7 changes: 3 additions & 4 deletions server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func listenEvents(c <-chan schedulerpkg.Event) {
for _, task := range job.Tasks {
if task.Name == event.Task {
task.Status = proto.TaskStatus_ABORTED
task.EndedAt = timestamppb.Now()
break
}
}
Expand All @@ -128,9 +129,7 @@ func listenEvents(c <-chan schedulerpkg.Event) {
if task.Name == event.Task {
task.Status = proto.TaskStatus_FAILED
task.ExitCode = lo.ToPtr(int32(event.ExitCode))
if event.ExitCode == 42 {
task.CompletedAt = timestamppb.Now()
}
task.EndedAt = timestamppb.Now()
break
}
}
Expand All @@ -144,7 +143,7 @@ func listenEvents(c <-chan schedulerpkg.Event) {
if task.Name == event.Task {
task.Status = proto.TaskStatus_COMPLETED
task.ExitCode = lo.ToPtr(int32(0))
task.CompletedAt = timestamppb.Now()
task.EndedAt = timestamppb.Now()
break
}
}
Expand Down

0 comments on commit a6daf6c

Please sign in to comment.