Skip to content

feat: unified retry/backoff policy shared across channels #7

Description

@cncoder

背景

`grep -r "exponentialBackoff|RetryPolicy" src/` 结果:没有共享实现。各 channel / plugin 自己实现重试逻辑,策略不一致:

  • Discord gateway: `ws` 内部重连(不受控)
  • Telegram: 手写 setTimeout
  • REST 调用: 部分裸调 undici

提案

在 `src/infra/retry/` 提取:

```ts
export class RetryPolicy {
constructor(opts: {
maxAttempts: number;
initialDelayMs: number;
maxDelayMs: number;
jitter: boolean;
retryOn: (err: unknown) => boolean;
}) {}
async execute(fn: () => Promise): Promise {}
}
```

默认策略:

  • 4xx 不重试(除 408/429)
  • 5xx 指数退避 + jitter
  • 网络错误(ECONNRESET/ETIMEDOUT)重试

各 channel 注入统一 policy,可被配置覆盖。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions