WaitInstanceState waits until the input instanceID is registered within the ring matching the provided state. A timeout should be provided within the context.
(ctx context.Context, r ReadRing, instanceID string, state InstanceState)
| 42 | // WaitInstanceState waits until the input instanceID is registered within the |
| 43 | // ring matching the provided state. A timeout should be provided within the context. |
| 44 | func WaitInstanceState(ctx context.Context, r ReadRing, instanceID string, state InstanceState) error { |
| 45 | backoff := backoff.New(ctx, backoff.Config{ |
| 46 | MinBackoff: 100 * time.Millisecond, |
| 47 | MaxBackoff: time.Second, |
| 48 | MaxRetries: 0, |
| 49 | }) |
| 50 | |
| 51 | for backoff.Ongoing() { |
| 52 | if actualState, err := r.GetInstanceState(instanceID); err == nil && actualState == state { |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | backoff.Wait() |
| 57 | } |
| 58 | |
| 59 | return backoff.Err() |
| 60 | } |
| 61 | |
| 62 | // WaitRingStability monitors the ring topology for the provided operation and waits until it |
| 63 | // keeps stable for at least minStability. |