Skip to content

Commit

Permalink
Retry on failed updates
Browse files Browse the repository at this point in the history
Signed-off-by: Byron Ruth <[email protected]>
  • Loading branch information
bruth committed Nov 3, 2023
1 parent 5922299 commit f1225c0
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/drivers/nats/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,26 @@ func getOrCreateBucket(ctx context.Context, js jetstream.JetStream, config *Conf
}

func disableDirectGets(ctx context.Context, js jetstream.JetStream, config *Config) error {
str, err := js.Stream(ctx, fmt.Sprintf("KV_%s", config.bucket))
if err != nil {
return fmt.Errorf("failed to get stream info: %w", err)
}
scfg := str.CachedInfo().Config
scfg.AllowDirect = false
for {
str, err := js.Stream(ctx, fmt.Sprintf("KV_%s", config.bucket))
if errors.Is(err, context.DeadlineExceeded) {
continue
}
if err != nil {
return fmt.Errorf("failed to get stream info: %w", err)
}

_, err = js.UpdateStream(ctx, scfg)
if err != nil {
return fmt.Errorf("failed to update stream config: %w", err)
}
scfg := str.CachedInfo().Config
scfg.AllowDirect = false

_, err = js.UpdateStream(ctx, scfg)
if errors.Is(err, context.DeadlineExceeded) {
continue
}
if err != nil {
return fmt.Errorf("failed to update stream config: %w", err)
}

return nil
return nil
}
}

0 comments on commit f1225c0

Please sign in to comment.