Skip to content

Commit

Permalink
Workflow end at time of last job completion (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
MNThomson committed Feb 20, 2024
1 parent 90c35e3 commit c29b66c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 9 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ func getConfig() (configType, error) {
return configType{}, fmt.Errorf("invalid env: GITHUB_REPOSITORY")
}

headersSplit := strings.Split(headers, ":")
if len(headersSplit) != 2 {
return configType{}, fmt.Errorf("invalid env: OTEL_EXPORTER_HEADERS")
}
headersMap := map[string]string{}

headersSplit := strings.Split(headers, ",")
for i := 0; i < len(headersSplit); i++ {
splitHeaders := strings.Split(headersSplit[i], ":")
if len(splitHeaders) != 2 {
return configType{}, fmt.Errorf("invalid env: OTEL_EXPORTER_HEADERS")
}
headersMap[splitHeaders[0]] = splitHeaders[1]

headersMap := map[string]string{
headersSplit[0]: headersSplit[1],
}

return configType{
Expand Down
6 changes: 5 additions & 1 deletion gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func createTraces(ctx context.Context, conf configType) error {
return err
}

var lastJobFinishesAt time.Time
ctx, workflowSpan := tracer.Start(ctx, *workflowData.Name, trace.WithTimestamp(workflowData.GetCreatedAt().Time))
for _, job := range jobs.Jobs {
ctx, jobSpan := tracer.Start(ctx, *job.Name, trace.WithTimestamp(job.GetStartedAt().Time))
Expand All @@ -45,6 +46,9 @@ func createTraces(ctx context.Context, conf configType) error {

if step.CompletedAt != nil {
stepSpan.End(trace.WithTimestamp(step.GetCompletedAt().Time))
if step.GetCompletedAt().Time.After(lastJobFinishesAt) {
lastJobFinishesAt = step.GetCompletedAt().Time
}
} else {
stepSpan.End()
}
Expand All @@ -56,7 +60,7 @@ func createTraces(ctx context.Context, conf configType) error {
jobSpan.End()
}
}
workflowSpan.End(trace.WithTimestamp(time.Now()))
workflowSpan.End(trace.WithTimestamp(lastJobFinishesAt))

return nil
}

0 comments on commit c29b66c

Please sign in to comment.