Skip to content

Commit

Permalink
avoid time.Sleep to log analysis timeout status
Browse files Browse the repository at this point in the history
Previously, to warn the user that the analysis is still running, we used
time.Sleep to print how much time is left for the timeout, however, if the
analysis has already been completed, we still need to wait for the end of
time.Sleep to finish the analysis. This change removes time.Sleep and uses
time.Tick to print the message, so, if the analysis is finished before the
next retry, we do not lock the analysis with time.Sleep.
  • Loading branch information
matheusalcantarazup committed Jun 23, 2021
1 parent ec7ef10 commit 0fa6f68
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/controllers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func (a *Analyzer) startDetectVulnerabilities(langs []languages.Language) {
timeout := a.config.GetTimeoutInSecondsAnalysis()
timer := time.After(time.Duration(timeout) * time.Second)
retry := a.config.GetMonitorRetryInSeconds()
tick := time.Tick(time.Duration(retry) * time.Second)
logger.LogInfoWithLevel(fmt.Sprintf("%s%ds", messages.MsgInfoMonitorTimeoutIn, timeout))
for {
select {
case <-done:
Expand All @@ -215,11 +217,9 @@ func (a *Analyzer) startDetectVulnerabilities(langs []languages.Language) {
a.docker.DeleteContainersFromAPI()
a.config.SetIsTimeout(true)
return
default:
msg := fmt.Sprintf("%s%ds", messages.MsgInfoMonitorTimeoutIn, timeout)
logger.LogInfoWithLevel(msg)
time.Sleep(time.Duration(retry) * time.Second)
case <-tick:
timeout -= retry
logger.LogInfoWithLevel(fmt.Sprintf("%s%ds", messages.MsgInfoMonitorTimeoutIn, timeout))
}
}
}
Expand Down

0 comments on commit 0fa6f68

Please sign in to comment.