Skip to content

Commit

Permalink
Merge 15a2e28 into 2305316
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- authored Feb 25, 2023
2 parents 2305316 + 15a2e28 commit a3236cc
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,17 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
// Init has passed successfully, so unless disabled, make sure we send a
// usage report after the context is done.
if !conf.NoUsageReport.Bool {
backgroundProcesses.Add(2)
reportCtx, reportCancel := context.WithCancel(globalCtx)
reportDone := make(chan error)
backgroundProcesses.Add(1)
go func() {
defer backgroundProcesses.Done()
reportCtx, reportCancel := context.WithTimeout(globalCtx, 3*time.Second)
defer reportCancel()
logger.Debug("Sending usage report...")
reportDone <- reportUsage(reportCtx, execScheduler)
close(reportDone)
backgroundProcesses.Done()
}()
go func() {
select {
case <-reportDone:
case <-time.After(3 * time.Second):
if rerr := reportUsage(reportCtx, execScheduler); rerr != nil {
logger.WithError(rerr).Debug("Error sending usage report")
} else {
logger.Debug("Usage report sent successfully")
}
reportCancel()
backgroundProcesses.Done()
}()
}

Expand Down

0 comments on commit a3236cc

Please sign in to comment.