Skip to content

Commit

Permalink
Save task duration correctly (vercel#4540)
Browse files Browse the repository at this point in the history
The bug is the `tracer()` updates duration every time you call it, and
we hadn't called it after task execution. I'm adding a new state to get
this timestamp. We cannot use `TargetBuilt` because we don't want to
capture that state until _after_ cache is saved, and, conversely, we
don't want to include the time to save the cache in the task duration.
  • Loading branch information
mehulkar authored and NicholasLYang committed Apr 21, 2023
1 parent 7abc46b commit 516d19a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cli/integration_tests/cache_state.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ Run a build to get a local cache.
Time:\s+[.0-9]+m?s (re)


Validate cache state according to dry-run
$ ${TURBO} run build --dry=json | jq '.tasks | map(select(.taskId == "my-app#build")) | .[0].cache'
Do a dry run so we can see the state of the cache
$ ${TURBO} run build --dry=json > dry.json

Get the hash of the my-app#build task, so we can inspect the cache
$ HASH=$(cat dry.json | jq -r '.tasks | map(select(.taskId == "my-app#build")) | .[0].hash')
$ duration=$(cat "node_modules/.cache/turbo/$HASH-meta.json" | jq .duration)
check that it exists
$ echo $duration
[0-9]+ (re)
should not be 0
$ test $duration != 0

Validate that local cache is true in dry run
$ cat dry.json | jq '.tasks | map(select(.taskId == "my-app#build")) | .[0].cache'
{
"local": true,
"remote": false
Expand Down
3 changes: 3 additions & 0 deletions cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
return taskExecutionSummary, err
}

// Add another timestamp into the tracer, so we have an accurate timestamp for how long the task took.
tracer(runsummary.TargetExecuted, nil, nil)

// Close off our outputs and cache them
if err := closeOutputs(); err != nil {
ec.logError("", err)
Expand Down
3 changes: 3 additions & 0 deletions cli/internal/runsummary/execution_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
targetInitialized executionEventName = iota
TargetBuilding
TargetBuildStopped
TargetExecuted
TargetBuilt
TargetCached
TargetBuildFailed
Expand All @@ -52,6 +53,8 @@ func (en executionEventName) toString() string {
return "building"
case TargetBuildStopped:
return "buildStopped"
case TargetExecuted:
return "executed"
case TargetBuilt:
return "built"
case TargetCached:
Expand Down

0 comments on commit 516d19a

Please sign in to comment.