(opts: {
provider: string
parse: (error: unknown) => Err
set: (input: { attempt: number; message: string; action?: Retryable["action"]; next: number }) => Effect.Effect<void>
})
| 174 | } |
| 175 | |
| 176 | export function policy(opts: { |
| 177 | provider: string |
| 178 | parse: (error: unknown) => Err |
| 179 | set: (input: { attempt: number; message: string; action?: Retryable["action"]; next: number }) => Effect.Effect<void> |
| 180 | }) { |
| 181 | return Schedule.fromStepWithMetadata( |
| 182 | Effect.succeed((meta: Schedule.InputMetadata<unknown>) => { |
| 183 | const error = opts.parse(meta.input) |
| 184 | const retry = retryable(error, opts.provider) |
| 185 | if (!retry) return Cause.done(meta.attempt) |
| 186 | return Effect.gen(function* () { |
| 187 | const wait = delay(meta.attempt, SessionV1.APIError.isInstance(error) ? error : undefined) |
| 188 | const now = yield* Clock.currentTimeMillis |
| 189 | yield* opts.set({ |
| 190 | attempt: meta.attempt, |
| 191 | message: retry.message, |
| 192 | action: retry.action, |
| 193 | next: now + wait, |
| 194 | }) |
| 195 | return [meta.attempt, Duration.millis(wait)] as [number, Duration.Duration] |
| 196 | }) |
| 197 | }), |
| 198 | ) |
| 199 | } |
| 200 | |
| 201 | export * as SessionRetry from "./retry" |
nothing calls this directly
no test coverage detected