fix: recover gateway callbacks and client send flows
This commit is contained in:
@@ -43,12 +43,24 @@ func (o *Outbox) Run(ctx context.Context) error {
|
||||
if strings.TrimSpace(o.APIBaseURL) == "" {
|
||||
return fmt.Errorf("result Outbox API base URL is required")
|
||||
}
|
||||
if o.BatchEnabled {
|
||||
return retryUntilCanceled(ctx, time.Second, func() error {
|
||||
if err := o.ensureGroup(ctx); err != nil {
|
||||
log.Printf("gateway result Outbox group initialization failed: %v", err)
|
||||
return err
|
||||
}
|
||||
if err := o.runBatches(ctx); err != nil && ctx.Err() == nil {
|
||||
// A transient Redis read error must not permanently stop the only
|
||||
// consumer for submit results, receipts, and uplink events.
|
||||
log.Printf("gateway result Outbox batch consume failed: %v", err)
|
||||
return err
|
||||
}
|
||||
return ctx.Err()
|
||||
})
|
||||
}
|
||||
if err := o.ensureGroup(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if o.BatchEnabled {
|
||||
return o.runBatches(ctx)
|
||||
}
|
||||
pool := newCallbackPool(ctx, o, o.concurrency())
|
||||
defer pool.wait()
|
||||
for {
|
||||
@@ -276,3 +288,12 @@ func sleep(ctx context.Context, duration time.Duration) {
|
||||
case <-timer.C:
|
||||
}
|
||||
}
|
||||
|
||||
func retryUntilCanceled(ctx context.Context, delay time.Duration, operation func() error) error {
|
||||
for ctx.Err() == nil {
|
||||
if err := operation(); err != nil && ctx.Err() == nil {
|
||||
sleep(ctx, delay)
|
||||
}
|
||||
}
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user