X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f049ebcb40b5509413f73840ead3ef8893f9331b..2c5a3dbd6b56ca39d7b105b821f7061d2b102a56:/lib/controller/trash.go diff --git a/lib/controller/trash.go b/lib/controller/trash.go index d1a54b4238..662ea26751 100644 --- a/lib/controller/trash.go +++ b/lib/controller/trash.go @@ -25,7 +25,7 @@ func (h *Handler) periodicWorker(workerName string, interval time.Duration, lock return } defer locker.Unlock() - for time.Sleep(interval); ctx.Err() == nil; time.Sleep(interval) { + for ctxSleep(ctx, interval); ctx.Err() == nil; ctxSleep(ctx, interval) { if !locker.Check() { // context canceled return @@ -85,3 +85,12 @@ DELETE FROM logs return nil }) } + +// Sleep for the given duration, but return early if ctx cancels +// before that. +func ctxSleep(ctx context.Context, d time.Duration) { + select { + case <-ctx.Done(): + case <-time.After(d): + } +}