Skip to content

Commit

Permalink
Merge pull request #328 from shanemcd/release-retry
Browse files Browse the repository at this point in the history
Retry when errors occur while releasing work
  • Loading branch information
shanemcd authored May 24, 2021
2 parents bd1d163 + 71fab58 commit 786296d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/workceptor/workunitbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,25 @@ func (bwu *BaseWorkUnit) UnredactedStatus() *StatusFileData {
func (bwu *BaseWorkUnit) Release(force bool) error {
bwu.statusLock.Lock()
defer bwu.statusLock.Unlock()
err := os.RemoveAll(bwu.UnitDir())
if err != nil && !force {
return err
attemptsLeft := 3
for {
err := os.RemoveAll(bwu.UnitDir())
if force {
break
} else if err != nil {
attemptsLeft--

if attemptsLeft > 0 {
logger.Warning("Error removing directory for %s. Retrying %d more times.", bwu.unitID, attemptsLeft)
time.Sleep(time.Second)
continue
} else {
logger.Error("Error removing directory for %s. No more retries left.", bwu.unitID)
return err
}
}

break
}
bwu.w.activeUnitsLock.Lock()
defer bwu.w.activeUnitsLock.Unlock()
Expand Down

0 comments on commit 786296d

Please sign in to comment.