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