2
2
package runsummary
3
3
4
4
import (
5
+ "context"
5
6
"encoding/json"
6
7
"fmt"
7
8
"path/filepath"
@@ -11,6 +12,7 @@ import (
11
12
"github.com/mitchellh/cli"
12
13
"github.com/segmentio/ksuid"
13
14
"github.com/vercel/turbo/cli/internal/client"
15
+ "github.com/vercel/turbo/cli/internal/spinner"
14
16
"github.com/vercel/turbo/cli/internal/turbopath"
15
17
"github.com/vercel/turbo/cli/internal/util"
16
18
"github.com/vercel/turbo/cli/internal/workspace"
@@ -124,7 +126,7 @@ func (rsm *Meta) getPath() turbopath.AbsoluteSystemPath {
124
126
}
125
127
126
128
// Close wraps up the RunSummary at the end of a `turbo run`.
127
- func (rsm * Meta ) Close (exitCode int , workspaceInfos workspace.Catalog ) error {
129
+ func (rsm * Meta ) Close (ctx context. Context , exitCode int , workspaceInfos workspace.Catalog ) error {
128
130
if rsm .runType == runTypeDryJSON || rsm .runType == runTypeDryText {
129
131
return rsm .closeDryRun (workspaceInfos )
130
132
}
@@ -161,8 +163,19 @@ func (rsm *Meta) Close(exitCode int, workspaceInfos workspace.Catalog) error {
161
163
return nil
162
164
}
163
165
164
- url , errs := rsm .record ()
166
+ // Wrap the record function so we can hoist out url/errors but keep
167
+ // the function signature/type the spinner.WaitFor expects.
168
+ var url string
169
+ var errs []error
170
+ record := func () {
171
+ url , errs = rsm .record ()
172
+ }
173
+
174
+ func () {
175
+ _ = spinner .WaitFor (ctx , record , rsm .ui , "...sending run summary..." , 1000 * time .Millisecond )
176
+ }()
165
177
178
+ // After the spinner is done
166
179
if len (errs ) > 0 {
167
180
rsm .ui .Warn ("Errors recording run to Spaces" )
168
181
for _ , err := range errs {
@@ -234,7 +247,7 @@ func (rsm *Meta) record() (string, []error) {
234
247
payload := rsm .newSpacesRunCreatePayload ()
235
248
if startPayload , err := json .Marshal (payload ); err == nil {
236
249
if resp , err := rsm .apiClient .JSONPost (createRunEndpoint , startPayload ); err != nil {
237
- errs = append (errs , err )
250
+ errs = append (errs , fmt . Errorf ( "POST %s: %w" , createRunEndpoint , err ) )
238
251
} else {
239
252
if err := json .Unmarshal (resp , response ); err != nil {
240
253
errs = append (errs , fmt .Errorf ("Error unmarshaling response: %w" , err ))
@@ -250,7 +263,7 @@ func (rsm *Meta) record() (string, []error) {
250
263
if donePayload , err := json .Marshal (newSpacesDonePayload (rsm .RunSummary )); err == nil {
251
264
patchURL := fmt .Sprintf (runsPatchEndpoint , rsm .spaceID , response .ID )
252
265
if _ , err := rsm .apiClient .JSONPatch (patchURL , donePayload ); err != nil {
253
- errs = append (errs , fmt .Errorf ("Error marking run as done : %w" , err ))
266
+ errs = append (errs , fmt .Errorf ("PATCH %s : %w" , patchURL , err ))
254
267
}
255
268
}
256
269
}
0 commit comments