Skip to content

Commit 07e89ff

Browse files
authored
timeout job progress (#4468)
This PR aims at making sure that job progress is timed out correctly.
1 parent 96e99c9 commit 07e89ff

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cmd/util/printer/job_progress_printer.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
)
3030

3131
const PrintoutCanceledButRunningNormally string = "printout canceled but running normally"
32+
const PrintoutTimeoutButRunningNormally string = "but running normally"
3233

3334
type JobProgressPrinter struct {
3435
client clientv2.API
@@ -244,7 +245,7 @@ To cancel the job, run:
244245
var returnError error = nil
245246

246247
// Capture Ctrl + C if the user wants to finish the job early
247-
ctx, cancel := context.WithCancel(ctx)
248+
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
248249
signalChan := make(chan os.Signal, 2)
249250
signal.Notify(signalChan, util.ShutdownSignals...)
250251
defer func() {
@@ -280,8 +281,17 @@ To cancel the job, run:
280281
}
281282
cancel()
282283
case <-ctx.Done():
283-
return
284+
cmdShuttingDown = true
285+
cmd.SetOut(os.Stdout)
286+
287+
if !quiet {
288+
cmd.Println("\n\n\rPrintout canceled due to timeout (the job is still running).")
289+
cmd.Println(getMoreInfoString)
290+
cmd.Println(cancelString)
291+
}
292+
returnError = fmt.Errorf("%s", PrintoutCanceledButRunningNormally)
284293
}
294+
return
285295
}
286296
}()
287297

0 commit comments

Comments
 (0)