1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package storageprovisioner
8
// minRetryDelay is the minimum delay to apply
9
// to operation retries; this does not apply to
10
// the first attempt for operations.
11
const minRetryDelay = 30 * time.Second
13
// maxRetryDelay is the maximum delay to apply
14
// to operation retries. Retry delays will backoff
15
// up to this ceiling.
16
const maxRetryDelay = 30 * time.Minute
18
// scheduleOperations schedules the given operations
19
// by calculating the current time once, and then
20
// adding each operation's delay to that time. By
21
// calculating the current time once, we guarantee
22
// that operations with the same delay will be
24
func scheduleOperations(ctx *context, ops ...scheduleOp) {
28
now := ctx.config.Clock.Now()
29
for _, op := range ops {
32
ctx.schedule.Add(k, op, now.Add(d))
36
// scheduleOp is an interface implemented by schedule
38
type scheduleOp interface {
39
// key is the key for the operation; this
40
// must be unique among all operations.
43
// delay is the amount of time to delay
44
// before next executing the operation.
48
// exponentialBackoff is a type that can be embedded to implement the
49
// delay() method of scheduleOp, providing truncated binary exponential
50
// backoff for operations that may be rescheduled.
51
type exponentialBackoff struct {
55
func (s *exponentialBackoff) delay() time.Duration {
57
if s.d < minRetryDelay {
61
if s.d > maxRetryDelay {