| 37 | } |
| 38 | |
| 39 | func (i *instanceDeleteBackoff) ShouldProcess(key string) (bool, time.Time) { |
| 40 | backoff, loaded := i.muxes.LoadOrStore(key, &instanceBackOff{}) |
| 41 | if !loaded { |
| 42 | return true, time.Time{} |
| 43 | } |
| 44 | |
| 45 | ib := backoff.(*instanceBackOff) |
| 46 | ib.mux.Lock() |
| 47 | defer ib.mux.Unlock() |
| 48 | |
| 49 | if ib.lastRecordedFailureTime.IsZero() || ib.backoffSeconds == 0 { |
| 50 | return true, time.Time{} |
| 51 | } |
| 52 | |
| 53 | now := time.Now().UTC() |
| 54 | deadline := ib.lastRecordedFailureTime.Add(time.Duration(ib.backoffSeconds) * time.Second) |
| 55 | return now.After(deadline), deadline |
| 56 | } |
| 57 | |
| 58 | func (i *instanceDeleteBackoff) Delete(key string) { |
| 59 | i.muxes.Delete(key) |