mirror of
https://github.com/restic/restic.git
synced 2024-12-23 08:16:36 +00:00
Add function to notify of success after retrying
This commit is contained in:
parent
c169e37139
commit
d629333efe
1 changed files with 19 additions and 0 deletions
|
@ -32,6 +32,25 @@ func NewRetryBackend(be restic.Backend, maxTries int, report func(string, error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retryNotifyErrorWithSuccess is an extension of backoff.RetryNotify with notification of success after an error
|
||||||
|
// success is NOT notified on the first run of operation (only after an error)
|
||||||
|
func retryNotifyErrorWithSuccess(operation backoff.Operation, b backoff.BackOff, notify backoff.Notify, success func()) error {
|
||||||
|
if success == nil {
|
||||||
|
return backoff.RetryNotify(operation, b, notify)
|
||||||
|
}
|
||||||
|
errorDetected := false
|
||||||
|
operationWrapper := func() error {
|
||||||
|
err := operation()
|
||||||
|
if err != nil {
|
||||||
|
errorDetected = true
|
||||||
|
} else if errorDetected {
|
||||||
|
success()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return backoff.RetryNotify(operationWrapper, b, notify)
|
||||||
|
}
|
||||||
|
|
||||||
func (be *RetryBackend) retry(ctx context.Context, msg string, f func() error) error {
|
func (be *RetryBackend) retry(ctx context.Context, msg string, f func() error) error {
|
||||||
// Don't do anything when called with an already cancelled context. There would be
|
// Don't do anything when called with an already cancelled context. There would be
|
||||||
// no retries in that case either, so be consistent and abort always.
|
// no retries in that case either, so be consistent and abort always.
|
||||||
|
|
Loading…
Reference in a new issue