fix: recover gateway callbacks and client send flows

This commit is contained in:
hectorzhao
2026-08-27 14:30:02 +08:00
parent a280b4bb22
commit d6edb88b76
10 changed files with 167 additions and 10 deletions
+24 -3
View File
@@ -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()
}