Skip to content

Commit

Permalink
Make attempted include tasks that started but didn't finish (#4378)
Browse files Browse the repository at this point in the history
The purpose of this is to

- account for tasks that somehow don't hit the `tracer()` function and
get marked as done by the time the whole run is done. This is very unlikely.
- account for new states we may want to add
- makes `attempted` more semantically correct. If we started, there was
an attempt! It doesn't matter what state we ended up in.
  • Loading branch information
mehulkar authored Mar 29, 2023
1 parent c65b5d6 commit 4e626df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
return nil, nil
}

// Set building status now that we know it's going to run.
tracer(runsummary.TargetBuilding, nil, &successCode)

var prefix string
var prettyPrefix string
if ec.rs.Opts.runOpts.logPrefix == "none" {
Expand Down
22 changes: 12 additions & 10 deletions cli/internal/runsummary/execution_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type executionEventName int

// The collection of expected build result statuses.
const (
targetBuilding executionEventName = iota
targetInitialized executionEventName = iota
TargetBuilding
TargetBuildStopped
TargetBuilt
TargetCached
Expand All @@ -44,7 +45,9 @@ const (

func (en executionEventName) toString() string {
switch en {
case targetBuilding:
case targetInitialized:
return "initialized"
case TargetBuilding:
return "building"
case TargetBuildStopped:
return "buildStopped"
Expand Down Expand Up @@ -107,10 +110,10 @@ type executionSummary struct {
profileFilename string

// These get serialized to JSON
success int
failure int
cached int
attempted int
success int // number of tasks that exited successfully (does not include cache hits)
failure int // number of tasks that exited with failure
cached int // number of tasks that had a cache hit
attempted int // number of tasks that started
startedAt time.Time
endedAt time.Time
exitCode int
Expand Down Expand Up @@ -164,7 +167,7 @@ func (es *executionSummary) run(taskID string) (func(outcome executionEventName,
taskExecutionSummary := es.add(&executionEvent{
Time: start,
Label: taskID,
Status: targetBuilding,
Status: targetInitialized,
})

tracer := chrometracing.Event(taskID)
Expand Down Expand Up @@ -219,15 +222,14 @@ func (es *executionSummary) add(event *executionEvent) *TaskExecutionSummary {
}

switch {
case event.Status == TargetBuilding:
es.attempted++
case event.Status == TargetBuildFailed:
es.failure++
es.attempted++
case event.Status == TargetCached:
es.cached++
es.attempted++
case event.Status == TargetBuilt:
es.success++
es.attempted++
}

return es.tasks[event.Label]
Expand Down
18 changes: 13 additions & 5 deletions cli/internal/runsummary/format_execution_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ func (rsm *Meta) printExecutionSummary() {
summary := rsm.RunSummary
ui := rsm.ui

if summary.ExecutionSummary.cached == summary.ExecutionSummary.attempted && summary.ExecutionSummary.attempted > 0 {
attempted := summary.ExecutionSummary.attempted
successful := summary.ExecutionSummary.cached + summary.ExecutionSummary.success
cached := summary.ExecutionSummary.cached
// TODO: can we use a method on ExecutionSummary here?
duration := time.Since(summary.ExecutionSummary.startedAt).Truncate(time.Millisecond)

if cached == attempted && attempted > 0 {
terminalProgram := os.Getenv("TERM_PROGRAM")
// On the macOS Terminal, the rainbow colors show up as a magenta background
// with a gray background on a single letter. Instead, we print in bold magenta
Expand All @@ -26,14 +32,16 @@ func (rsm *Meta) printExecutionSummary() {
}
}

if summary.ExecutionSummary.attempted == 0 {
if attempted == 0 {
ui.Output("") // Clear the line
ui.Warn("No tasks were executed as part of this run.")
}

ui.Output("") // Clear the line
ui.Output(util.Sprintf("${BOLD} Tasks:${BOLD_GREEN} %v successful${RESET}${GRAY}, %v total${RESET}", summary.ExecutionSummary.cached+summary.ExecutionSummary.success, summary.ExecutionSummary.attempted))
ui.Output(util.Sprintf("${BOLD}Cached: %v cached${RESET}${GRAY}, %v total${RESET}", summary.ExecutionSummary.cached, summary.ExecutionSummary.attempted))
ui.Output(util.Sprintf("${BOLD} Time: %v${RESET} %v${RESET}", time.Since(summary.ExecutionSummary.startedAt).Truncate(time.Millisecond), maybeFullTurbo))

// The whitespaces in the string are to align the UI in a nice way.
ui.Output(util.Sprintf("${BOLD} Tasks:${BOLD_GREEN} %v successful${RESET}${GRAY}, %v total${RESET}", successful, attempted))
ui.Output(util.Sprintf("${BOLD}Cached: %v cached${RESET}${GRAY}, %v total${RESET}", cached, attempted))
ui.Output(util.Sprintf("${BOLD} Time: %v${RESET} %v${RESET}", duration, maybeFullTurbo))
ui.Output("")
}

0 comments on commit 4e626df

Please sign in to comment.