1
0
Fork 0

Move jobs backoff back into traefik

https://github.com/cenk/backoff/pull/27#issuecomment-245842725
This commit is contained in:
Emile Vauge 2016-09-19 19:08:39 +02:00
parent 1b6af2045e
commit 364958cbaf
No known key found for this signature in database
GPG key ID: D808B4C167352E59
11 changed files with 213 additions and 124 deletions

39
job/job.go Normal file
View file

@ -0,0 +1,39 @@
package job
import (
"github.com/cenk/backoff"
"time"
)
var (
_ backoff.BackOff = (*BackOff)(nil)
)
const (
defaultMinJobInterval = 30 * time.Second
)
// BackOff is an exponential backoff implementation for long running jobs.
// In long running jobs, an operation() that fails after a long Duration should not increments the backoff period.
// If operation() takes more than MinJobInterval, Reset() is called in NextBackOff().
type BackOff struct {
*backoff.ExponentialBackOff
MinJobInterval time.Duration
}
// NewBackOff creates an instance of BackOff using default values.
func NewBackOff(backOff *backoff.ExponentialBackOff) *BackOff {
backOff.MaxElapsedTime = 0
return &BackOff{
ExponentialBackOff: backOff,
MinJobInterval: defaultMinJobInterval,
}
}
// NextBackOff calculates the next backoff interval.
func (b *BackOff) NextBackOff() time.Duration {
if b.GetElapsedTime() >= b.MinJobInterval {
b.Reset()
}
return b.ExponentialBackOff.NextBackOff()
}