reqon-dsl 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +31 -0
- package/.claude/skills/api-integration.md +125 -0
- package/.claude/skills/database-schema.md +51 -0
- package/.claude/skills/dsl-design.md +80 -0
- package/.claude/skills/property-testing.md +143 -0
- package/.claude/skills/reqon/SKILL.md +44 -0
- package/.claude/skills/reqon/references/examples.md +206 -0
- package/.claude/skills/reqon/references/syntax.md +263 -0
- package/.claude/skills/vscode-extension.md +113 -0
- package/.github/dependabot.yml +32 -0
- package/.github/pull_request_template.md +21 -0
- package/.github/workflows/ci.yml +174 -0
- package/.github/workflows/release.yml +73 -0
- package/CLAUDE.md +72 -0
- package/CONTRIBUTING.md +161 -0
- package/README.md +235 -0
- package/TODO.md +51 -0
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/ast/nodes.d.ts +237 -0
- package/dist/ast/nodes.js +12 -0
- package/dist/auth/auth.test.d.ts +1 -0
- package/dist/auth/auth.test.js +255 -0
- package/dist/auth/circuit-breaker.d.ts +115 -0
- package/dist/auth/circuit-breaker.js +267 -0
- package/dist/auth/credentials.d.ts +91 -0
- package/dist/auth/credentials.js +169 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/oauth2-provider.d.ts +41 -0
- package/dist/auth/oauth2-provider.js +131 -0
- package/dist/auth/rate-limiter.d.ts +61 -0
- package/dist/auth/rate-limiter.js +380 -0
- package/dist/auth/token-store.d.ts +30 -0
- package/dist/auth/token-store.js +148 -0
- package/dist/auth/types.d.ts +142 -0
- package/dist/auth/types.js +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +270 -0
- package/dist/errors/errors.test.d.ts +1 -0
- package/dist/errors/errors.test.js +165 -0
- package/dist/errors/index.d.ts +83 -0
- package/dist/errors/index.js +159 -0
- package/dist/execution/execution.test.d.ts +1 -0
- package/dist/execution/execution.test.js +246 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/state.d.ts +136 -0
- package/dist/execution/state.js +82 -0
- package/dist/execution/store.d.ts +52 -0
- package/dist/execution/store.js +120 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +57 -0
- package/dist/integration.test.d.ts +1 -0
- package/dist/integration.test.js +168 -0
- package/dist/interpreter/context.d.ts +15 -0
- package/dist/interpreter/context.js +29 -0
- package/dist/interpreter/evaluator.d.ts +5 -0
- package/dist/interpreter/evaluator.js +223 -0
- package/dist/interpreter/evaluator.test.d.ts +1 -0
- package/dist/interpreter/evaluator.test.js +512 -0
- package/dist/interpreter/executor.d.ts +131 -0
- package/dist/interpreter/executor.js +663 -0
- package/dist/interpreter/fetch-handler.d.ts +43 -0
- package/dist/interpreter/fetch-handler.js +203 -0
- package/dist/interpreter/http.d.ts +57 -0
- package/dist/interpreter/http.js +210 -0
- package/dist/interpreter/http.test.d.ts +1 -0
- package/dist/interpreter/http.test.js +299 -0
- package/dist/interpreter/index.d.ts +7 -0
- package/dist/interpreter/index.js +7 -0
- package/dist/interpreter/pagination.d.ts +63 -0
- package/dist/interpreter/pagination.js +155 -0
- package/dist/interpreter/progress.test.d.ts +1 -0
- package/dist/interpreter/progress.test.js +216 -0
- package/dist/interpreter/schema-matcher.d.ts +16 -0
- package/dist/interpreter/schema-matcher.js +136 -0
- package/dist/interpreter/schema-matcher.test.d.ts +1 -0
- package/dist/interpreter/schema-matcher.test.js +122 -0
- package/dist/interpreter/signals.d.ts +57 -0
- package/dist/interpreter/signals.js +73 -0
- package/dist/interpreter/step-handlers/for-handler.d.ts +17 -0
- package/dist/interpreter/step-handlers/for-handler.js +51 -0
- package/dist/interpreter/step-handlers/index.d.ts +8 -0
- package/dist/interpreter/step-handlers/index.js +8 -0
- package/dist/interpreter/step-handlers/map-handler.d.ts +10 -0
- package/dist/interpreter/step-handlers/map-handler.js +20 -0
- package/dist/interpreter/step-handlers/match-handler.d.ts +27 -0
- package/dist/interpreter/step-handlers/match-handler.js +61 -0
- package/dist/interpreter/step-handlers/store-handler.d.ts +13 -0
- package/dist/interpreter/step-handlers/store-handler.js +66 -0
- package/dist/interpreter/step-handlers/types.d.ts +15 -0
- package/dist/interpreter/step-handlers/types.js +1 -0
- package/dist/interpreter/step-handlers/validate-handler.d.ts +10 -0
- package/dist/interpreter/step-handlers/validate-handler.js +26 -0
- package/dist/interpreter/step-handlers/webhook-handler.d.ts +36 -0
- package/dist/interpreter/step-handlers/webhook-handler.js +104 -0
- package/dist/lexer/index.d.ts +10 -0
- package/dist/lexer/index.js +12 -0
- package/dist/lexer/lexer.d.ts +24 -0
- package/dist/lexer/lexer.js +264 -0
- package/dist/lexer/lexer.test.d.ts +1 -0
- package/dist/lexer/lexer.test.js +259 -0
- package/dist/lexer/tokens.d.ts +69 -0
- package/dist/lexer/tokens.js +146 -0
- package/dist/loader/index.d.ts +36 -0
- package/dist/loader/index.js +220 -0
- package/dist/loader/loader.test.d.ts +1 -0
- package/dist/loader/loader.test.js +287 -0
- package/dist/oas/index.d.ts +4 -0
- package/dist/oas/index.js +2 -0
- package/dist/oas/loader.d.ts +21 -0
- package/dist/oas/loader.js +82 -0
- package/dist/oas/oas.test.d.ts +1 -0
- package/dist/oas/oas.test.js +218 -0
- package/dist/oas/validator.d.ts +12 -0
- package/dist/oas/validator.js +227 -0
- package/dist/parser/base.d.ts +33 -0
- package/dist/parser/base.js +97 -0
- package/dist/parser/expressions.d.ts +27 -0
- package/dist/parser/expressions.js +248 -0
- package/dist/parser/expressions.test.d.ts +1 -0
- package/dist/parser/expressions.test.js +378 -0
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.js +3 -0
- package/dist/parser/match.test.d.ts +1 -0
- package/dist/parser/match.test.js +254 -0
- package/dist/parser/parser.d.ts +68 -0
- package/dist/parser/parser.js +1229 -0
- package/dist/parser/parser.test.d.ts +1 -0
- package/dist/parser/parser.test.js +333 -0
- package/dist/parser/schedule.test.d.ts +1 -0
- package/dist/parser/schedule.test.js +241 -0
- package/dist/plugin.d.ts +35 -0
- package/dist/plugin.js +68 -0
- package/dist/scheduler/cron-parser.d.ts +32 -0
- package/dist/scheduler/cron-parser.js +198 -0
- package/dist/scheduler/cron-parser.test.d.ts +1 -0
- package/dist/scheduler/cron-parser.test.js +188 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/scheduler.d.ts +81 -0
- package/dist/scheduler/scheduler.js +376 -0
- package/dist/scheduler/types.d.ts +65 -0
- package/dist/scheduler/types.js +1 -0
- package/dist/stores/factory.d.ts +36 -0
- package/dist/stores/factory.js +73 -0
- package/dist/stores/file.d.ts +60 -0
- package/dist/stores/file.js +173 -0
- package/dist/stores/file.test.d.ts +1 -0
- package/dist/stores/file.test.js +165 -0
- package/dist/stores/index.d.ts +6 -0
- package/dist/stores/index.js +5 -0
- package/dist/stores/memory.d.ts +19 -0
- package/dist/stores/memory.js +51 -0
- package/dist/stores/memory.test.d.ts +1 -0
- package/dist/stores/memory.test.js +157 -0
- package/dist/stores/postgrest.d.ts +55 -0
- package/dist/stores/postgrest.js +217 -0
- package/dist/stores/stores.test.d.ts +1 -0
- package/dist/stores/stores.test.js +158 -0
- package/dist/stores/types.d.ts +31 -0
- package/dist/stores/types.js +26 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/state.d.ts +69 -0
- package/dist/sync/state.js +66 -0
- package/dist/sync/store.d.ts +49 -0
- package/dist/sync/store.js +93 -0
- package/dist/sync/sync.test.d.ts +1 -0
- package/dist/sync/sync.test.js +221 -0
- package/dist/utils/async.d.ts +7 -0
- package/dist/utils/async.js +9 -0
- package/dist/utils/file.d.ts +38 -0
- package/dist/utils/file.js +92 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/logger.d.ts +34 -0
- package/dist/utils/logger.js +39 -0
- package/dist/utils/path.d.ts +12 -0
- package/dist/utils/path.js +41 -0
- package/dist/webhook/index.d.ts +8 -0
- package/dist/webhook/index.js +7 -0
- package/dist/webhook/server.d.ts +84 -0
- package/dist/webhook/server.js +319 -0
- package/dist/webhook/store.d.ts +67 -0
- package/dist/webhook/store.js +193 -0
- package/dist/webhook/types.d.ts +88 -0
- package/dist/webhook/types.js +6 -0
- package/docusaurus/README.md +41 -0
- package/docusaurus/docs/advanced/execution-state.md +283 -0
- package/docusaurus/docs/advanced/extending-reqon.md +388 -0
- package/docusaurus/docs/advanced/multi-file-missions.md +250 -0
- package/docusaurus/docs/advanced/parallel-execution.md +353 -0
- package/docusaurus/docs/api-reference.md +443 -0
- package/docusaurus/docs/authentication/api-key.md +339 -0
- package/docusaurus/docs/authentication/basic.md +276 -0
- package/docusaurus/docs/authentication/bearer.md +282 -0
- package/docusaurus/docs/authentication/oauth2.md +317 -0
- package/docusaurus/docs/authentication/overview.md +251 -0
- package/docusaurus/docs/cli.md +229 -0
- package/docusaurus/docs/core-concepts/actions.md +286 -0
- package/docusaurus/docs/core-concepts/missions.md +264 -0
- package/docusaurus/docs/core-concepts/schemas.md +353 -0
- package/docusaurus/docs/core-concepts/sources.md +339 -0
- package/docusaurus/docs/core-concepts/stores.md +332 -0
- package/docusaurus/docs/dsl-syntax/expressions.md +361 -0
- package/docusaurus/docs/dsl-syntax/fetch.md +293 -0
- package/docusaurus/docs/dsl-syntax/for-loops.md +324 -0
- package/docusaurus/docs/dsl-syntax/map.md +345 -0
- package/docusaurus/docs/dsl-syntax/match.md +387 -0
- package/docusaurus/docs/dsl-syntax/pipelines.md +397 -0
- package/docusaurus/docs/dsl-syntax/validate.md +401 -0
- package/docusaurus/docs/error-handling/dead-letter-queues.md +399 -0
- package/docusaurus/docs/error-handling/flow-control.md +337 -0
- package/docusaurus/docs/error-handling/retry-strategies.md +368 -0
- package/docusaurus/docs/examples.md +488 -0
- package/docusaurus/docs/getting-started.md +256 -0
- package/docusaurus/docs/http/circuit-breaker.md +401 -0
- package/docusaurus/docs/http/incremental-sync.md +394 -0
- package/docusaurus/docs/http/pagination.md +361 -0
- package/docusaurus/docs/http/rate-limiting.md +383 -0
- package/docusaurus/docs/http/requests.md +328 -0
- package/docusaurus/docs/http/retry.md +402 -0
- package/docusaurus/docs/intro.md +90 -0
- package/docusaurus/docs/openapi/loading-specs.md +305 -0
- package/docusaurus/docs/openapi/operation-calls.md +314 -0
- package/docusaurus/docs/openapi/overview.md +212 -0
- package/docusaurus/docs/openapi/response-validation.md +344 -0
- package/docusaurus/docs/scheduling/cron.md +305 -0
- package/docusaurus/docs/scheduling/daemon-mode.md +317 -0
- package/docusaurus/docs/scheduling/intervals.md +289 -0
- package/docusaurus/docs/scheduling/overview.md +231 -0
- package/docusaurus/docs/stores/custom-adapters.md +376 -0
- package/docusaurus/docs/stores/file.md +236 -0
- package/docusaurus/docs/stores/memory.md +193 -0
- package/docusaurus/docs/stores/overview.md +274 -0
- package/docusaurus/docs/stores/postgrest.md +316 -0
- package/docusaurus/docusaurus.config.ts +148 -0
- package/docusaurus/package-lock.json +18029 -0
- package/docusaurus/package.json +47 -0
- package/docusaurus/sidebars.ts +155 -0
- package/docusaurus/src/components/HomepageFeatures/index.tsx +105 -0
- package/docusaurus/src/components/HomepageFeatures/styles.module.css +12 -0
- package/docusaurus/src/css/custom.css +169 -0
- package/docusaurus/src/pages/index.module.css +48 -0
- package/docusaurus/src/pages/index.tsx +110 -0
- package/docusaurus/src/pages/markdown-page.md +7 -0
- package/docusaurus/static/.nojekyll +0 -0
- package/docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docusaurus/static/img/docusaurus.png +0 -0
- package/docusaurus/static/img/favicon.ico +0 -0
- package/docusaurus/static/img/logo.svg +10 -0
- package/docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docusaurus/tsconfig.json +8 -0
- package/examples/README.md +112 -0
- package/examples/error-handling/README.md +150 -0
- package/examples/error-handling/payment-processor.vague +287 -0
- package/examples/github-sync/README.md +74 -0
- package/examples/github-sync/fetch-issues.vague +47 -0
- package/examples/github-sync/fetch-prs.vague +40 -0
- package/examples/github-sync/mission.vague +101 -0
- package/examples/github-sync/normalize.vague +70 -0
- package/examples/jsonplaceholder/README.md +28 -0
- package/examples/jsonplaceholder/posts.vague +48 -0
- package/examples/petstore/README.md +35 -0
- package/examples/petstore/openapi.yaml +97 -0
- package/examples/petstore/sync.vague +52 -0
- package/examples/temporal-comparison/README.md +297 -0
- package/examples/temporal-comparison/reconciliation.vague +355 -0
- package/examples/temporal-comparison/temporal/activities/index.ts +8 -0
- package/examples/temporal-comparison/temporal/activities/shipstation.ts +225 -0
- package/examples/temporal-comparison/temporal/activities/shopify.ts +257 -0
- package/examples/temporal-comparison/temporal/activities/storage.ts +198 -0
- package/examples/temporal-comparison/temporal/activities/stripe.ts +169 -0
- package/examples/temporal-comparison/temporal/activities/validation.ts +205 -0
- package/examples/temporal-comparison/temporal/client/schedule.ts +218 -0
- package/examples/temporal-comparison/temporal/config/retry.ts +63 -0
- package/examples/temporal-comparison/temporal/types/index.ts +129 -0
- package/examples/temporal-comparison/temporal/workers/main.ts +130 -0
- package/examples/temporal-comparison/temporal/workflows/orderReconciliation.ts +262 -0
- package/examples/xero/README.md +88 -0
- package/examples/xero/invoices.vague +189 -0
- package/package.json +40 -0
- package/src/api-integration.test.ts +954 -0
- package/src/ast/index.ts +1 -0
- package/src/ast/nodes.ts +310 -0
- package/src/auth/auth.test.ts +326 -0
- package/src/auth/circuit-breaker.test.ts +390 -0
- package/src/auth/circuit-breaker.ts +379 -0
- package/src/auth/credentials.test.ts +273 -0
- package/src/auth/credentials.ts +246 -0
- package/src/auth/index.ts +40 -0
- package/src/auth/oauth2-provider.ts +177 -0
- package/src/auth/rate-limiter.ts +459 -0
- package/src/auth/token-store.ts +177 -0
- package/src/auth/types.ts +159 -0
- package/src/benchmark/e2e.bench.ts +288 -0
- package/src/benchmark/evaluator.bench.ts +331 -0
- package/src/benchmark/fixtures.ts +295 -0
- package/src/benchmark/index.ts +108 -0
- package/src/benchmark/lexer.bench.ts +69 -0
- package/src/benchmark/parser.bench.ts +103 -0
- package/src/benchmark/resilience.bench.ts +193 -0
- package/src/benchmark/store.bench.ts +147 -0
- package/src/benchmark/utils.ts +230 -0
- package/src/cli.ts +313 -0
- package/src/errors/errors.test.ts +234 -0
- package/src/errors/index.ts +223 -0
- package/src/execution/execution.test.ts +307 -0
- package/src/execution/index.ts +21 -0
- package/src/execution/state.ts +207 -0
- package/src/execution/store.ts +188 -0
- package/src/index.ts +169 -0
- package/src/integration.test.ts +192 -0
- package/src/interpreter/context.ts +57 -0
- package/src/interpreter/evaluator.test.ts +796 -0
- package/src/interpreter/evaluator.ts +245 -0
- package/src/interpreter/executor.ts +946 -0
- package/src/interpreter/fetch-handler.ts +302 -0
- package/src/interpreter/http.test.ts +423 -0
- package/src/interpreter/http.ts +308 -0
- package/src/interpreter/index.ts +32 -0
- package/src/interpreter/pagination.ts +207 -0
- package/src/interpreter/progress.test.ts +276 -0
- package/src/interpreter/schema-matcher.test.ts +160 -0
- package/src/interpreter/schema-matcher.ts +168 -0
- package/src/interpreter/signals.ts +73 -0
- package/src/interpreter/step-handlers/for-handler.ts +65 -0
- package/src/interpreter/step-handlers/index.ts +17 -0
- package/src/interpreter/step-handlers/map-handler.ts +24 -0
- package/src/interpreter/step-handlers/match-handler.ts +101 -0
- package/src/interpreter/step-handlers/store-handler.ts +78 -0
- package/src/interpreter/step-handlers/types.ts +17 -0
- package/src/interpreter/step-handlers/validate-handler.ts +30 -0
- package/src/interpreter/step-handlers/webhook-handler.ts +142 -0
- package/src/lexer/index.ts +18 -0
- package/src/lexer/lexer.test.ts +316 -0
- package/src/lexer/tokens.ts +179 -0
- package/src/loader/index.ts +288 -0
- package/src/loader/loader.test.ts +360 -0
- package/src/oas/index.ts +4 -0
- package/src/oas/loader.ts +126 -0
- package/src/oas/oas.test.ts +254 -0
- package/src/oas/validator.ts +299 -0
- package/src/parser/base.ts +124 -0
- package/src/parser/expressions.test.ts +525 -0
- package/src/parser/expressions.ts +314 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/match.test.ts +296 -0
- package/src/parser/parser.test.ts +739 -0
- package/src/parser/parser.ts +1469 -0
- package/src/parser/schedule.test.ts +287 -0
- package/src/parser/webhook.test.ts +248 -0
- package/src/plugin.ts +83 -0
- package/src/scheduler/cron-parser.test.ts +236 -0
- package/src/scheduler/cron-parser.ts +236 -0
- package/src/scheduler/index.ts +10 -0
- package/src/scheduler/scheduler.ts +443 -0
- package/src/scheduler/types.ts +71 -0
- package/src/stores/factory.ts +104 -0
- package/src/stores/file.test.ts +276 -0
- package/src/stores/file.ts +211 -0
- package/src/stores/index.ts +6 -0
- package/src/stores/memory.test.ts +238 -0
- package/src/stores/memory.ts +63 -0
- package/src/stores/postgrest.test.ts +488 -0
- package/src/stores/postgrest.ts +263 -0
- package/src/stores/stores.test.ts +197 -0
- package/src/stores/types.ts +58 -0
- package/src/sync/index.ts +16 -0
- package/src/sync/state.ts +126 -0
- package/src/sync/store.ts +139 -0
- package/src/sync/sync.test.ts +271 -0
- package/src/utils/async.ts +10 -0
- package/src/utils/file.ts +106 -0
- package/src/utils/index.ts +14 -0
- package/src/utils/logger.ts +53 -0
- package/src/utils/path.ts +47 -0
- package/src/webhook/index.ts +15 -0
- package/src/webhook/server.test.ts +253 -0
- package/src/webhook/server.ts +389 -0
- package/src/webhook/store.ts +239 -0
- package/src/webhook/types.ts +93 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +39 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 2
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Retry Strategies
|
|
6
|
+
|
|
7
|
+
Reqon provides configurable retry strategies for handling transient failures. Choose the right strategy based on your API's behavior.
|
|
8
|
+
|
|
9
|
+
## Retry Configuration
|
|
10
|
+
|
|
11
|
+
```vague
|
|
12
|
+
retry: {
|
|
13
|
+
maxAttempts: 5,
|
|
14
|
+
backoff: exponential,
|
|
15
|
+
initialDelay: 1000,
|
|
16
|
+
maxDelay: 60000
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Backoff Strategies
|
|
21
|
+
|
|
22
|
+
### Exponential Backoff
|
|
23
|
+
|
|
24
|
+
Best for most APIs. Delays double after each attempt:
|
|
25
|
+
|
|
26
|
+
```vague
|
|
27
|
+
match response {
|
|
28
|
+
{ code: 429 } -> retry {
|
|
29
|
+
maxAttempts: 5,
|
|
30
|
+
backoff: exponential,
|
|
31
|
+
initialDelay: 1000
|
|
32
|
+
},
|
|
33
|
+
_ -> continue
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Timeline:
|
|
38
|
+
```
|
|
39
|
+
Attempt 1: immediate
|
|
40
|
+
Attempt 2: wait 1000ms (1s)
|
|
41
|
+
Attempt 3: wait 2000ms (2s)
|
|
42
|
+
Attempt 4: wait 4000ms (4s)
|
|
43
|
+
Attempt 5: wait 8000ms (8s)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Linear Backoff
|
|
47
|
+
|
|
48
|
+
Delays increase by a fixed amount:
|
|
49
|
+
|
|
50
|
+
```vague
|
|
51
|
+
match response {
|
|
52
|
+
{ code: 503 } -> retry {
|
|
53
|
+
maxAttempts: 5,
|
|
54
|
+
backoff: linear,
|
|
55
|
+
initialDelay: 2000
|
|
56
|
+
},
|
|
57
|
+
_ -> continue
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Timeline:
|
|
62
|
+
```
|
|
63
|
+
Attempt 1: immediate
|
|
64
|
+
Attempt 2: wait 2000ms (2s)
|
|
65
|
+
Attempt 3: wait 4000ms (4s)
|
|
66
|
+
Attempt 4: wait 6000ms (6s)
|
|
67
|
+
Attempt 5: wait 8000ms (8s)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Constant Backoff
|
|
71
|
+
|
|
72
|
+
Same delay every time:
|
|
73
|
+
|
|
74
|
+
```vague
|
|
75
|
+
match response {
|
|
76
|
+
{ code: 504 } -> retry {
|
|
77
|
+
maxAttempts: 5,
|
|
78
|
+
backoff: constant,
|
|
79
|
+
initialDelay: 5000
|
|
80
|
+
},
|
|
81
|
+
_ -> continue
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Timeline:
|
|
86
|
+
```
|
|
87
|
+
Attempt 1: immediate
|
|
88
|
+
Attempt 2: wait 5000ms (5s)
|
|
89
|
+
Attempt 3: wait 5000ms (5s)
|
|
90
|
+
Attempt 4: wait 5000ms (5s)
|
|
91
|
+
Attempt 5: wait 5000ms (5s)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Maximum Delay
|
|
95
|
+
|
|
96
|
+
Prevent extremely long waits:
|
|
97
|
+
|
|
98
|
+
```vague
|
|
99
|
+
retry: {
|
|
100
|
+
maxAttempts: 10,
|
|
101
|
+
backoff: exponential,
|
|
102
|
+
initialDelay: 1000,
|
|
103
|
+
maxDelay: 30000 // Cap at 30 seconds
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Without cap (exponential):
|
|
108
|
+
```
|
|
109
|
+
Attempt 8: wait 128000ms (2+ min)
|
|
110
|
+
Attempt 9: wait 256000ms (4+ min)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
With `maxDelay: 30000`:
|
|
114
|
+
```
|
|
115
|
+
Attempt 8: wait 30000ms (30s)
|
|
116
|
+
Attempt 9: wait 30000ms (30s)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Fixed Delay
|
|
120
|
+
|
|
121
|
+
Override backoff calculation:
|
|
122
|
+
|
|
123
|
+
```vague
|
|
124
|
+
match response {
|
|
125
|
+
{ code: 429, retryAfter: seconds } -> retry {
|
|
126
|
+
maxAttempts: 5,
|
|
127
|
+
delay: seconds * 1000 // Use API-provided delay
|
|
128
|
+
},
|
|
129
|
+
_ -> continue
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Retry Based on Error Type
|
|
134
|
+
|
|
135
|
+
### Transient Errors (Should Retry)
|
|
136
|
+
|
|
137
|
+
```vague
|
|
138
|
+
match response {
|
|
139
|
+
{ code: 408 } -> retry, // Request Timeout
|
|
140
|
+
{ code: 429 } -> retry, // Too Many Requests
|
|
141
|
+
{ code: 500 } -> retry, // Internal Server Error
|
|
142
|
+
{ code: 502 } -> retry, // Bad Gateway
|
|
143
|
+
{ code: 503 } -> retry, // Service Unavailable
|
|
144
|
+
{ code: 504 } -> retry, // Gateway Timeout
|
|
145
|
+
_ -> continue
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Permanent Errors (Don't Retry)
|
|
150
|
+
|
|
151
|
+
```vague
|
|
152
|
+
match response {
|
|
153
|
+
{ code: 400 } -> abort "Bad request", // Won't improve
|
|
154
|
+
{ code: 401 } -> abort "Unauthorized", // Need new creds
|
|
155
|
+
{ code: 403 } -> abort "Forbidden", // Permission issue
|
|
156
|
+
{ code: 404 } -> skip, // Resource gone
|
|
157
|
+
{ code: 422 } -> abort "Invalid data", // Validation error
|
|
158
|
+
_ -> continue
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Conditional Retry
|
|
163
|
+
|
|
164
|
+
```vague
|
|
165
|
+
match response {
|
|
166
|
+
// Retry rate limits with longer wait
|
|
167
|
+
{ code: 429 } -> retry {
|
|
168
|
+
maxAttempts: 10,
|
|
169
|
+
backoff: exponential,
|
|
170
|
+
initialDelay: 60000 // Start at 1 minute
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
// Retry server errors with shorter wait
|
|
174
|
+
{ code: 500 } -> retry {
|
|
175
|
+
maxAttempts: 3,
|
|
176
|
+
backoff: exponential,
|
|
177
|
+
initialDelay: 1000
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
// Retry timeouts with medium wait
|
|
181
|
+
{ code: 504 } -> retry {
|
|
182
|
+
maxAttempts: 5,
|
|
183
|
+
backoff: linear,
|
|
184
|
+
initialDelay: 5000
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
_ -> continue
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Retry-After Header
|
|
192
|
+
|
|
193
|
+
Respect API's `Retry-After` header:
|
|
194
|
+
|
|
195
|
+
```vague
|
|
196
|
+
match response {
|
|
197
|
+
{ code: 429, headers: h } where h["Retry-After"] != null -> retry {
|
|
198
|
+
delay: toNumber(h["Retry-After"]) * 1000
|
|
199
|
+
},
|
|
200
|
+
{ code: 429 } -> retry {
|
|
201
|
+
maxAttempts: 5,
|
|
202
|
+
backoff: exponential,
|
|
203
|
+
initialDelay: 60000
|
|
204
|
+
},
|
|
205
|
+
_ -> continue
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Retry with Token Refresh
|
|
210
|
+
|
|
211
|
+
```vague
|
|
212
|
+
action FetchProtectedData {
|
|
213
|
+
get "/protected"
|
|
214
|
+
|
|
215
|
+
match response {
|
|
216
|
+
{ code: 401 } -> jump RefreshToken then retry,
|
|
217
|
+
{ code: 429 } -> retry { maxAttempts: 5 },
|
|
218
|
+
{ code: 500 } -> retry { maxAttempts: 3 },
|
|
219
|
+
_ -> continue
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
action RefreshToken {
|
|
224
|
+
post "/auth/refresh" {
|
|
225
|
+
body: { refreshToken: env("REFRESH_TOKEN") }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Retry at Source Level
|
|
231
|
+
|
|
232
|
+
Configure default retry for all requests:
|
|
233
|
+
|
|
234
|
+
```vague
|
|
235
|
+
source API {
|
|
236
|
+
auth: bearer,
|
|
237
|
+
base: "https://api.example.com",
|
|
238
|
+
retry: {
|
|
239
|
+
maxAttempts: 3,
|
|
240
|
+
backoff: exponential,
|
|
241
|
+
initialDelay: 1000
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Override per request:
|
|
247
|
+
|
|
248
|
+
```vague
|
|
249
|
+
get "/critical-endpoint" {
|
|
250
|
+
retry: {
|
|
251
|
+
maxAttempts: 10 // More attempts for critical requests
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Choosing the Right Strategy
|
|
257
|
+
|
|
258
|
+
| Scenario | Recommended Strategy |
|
|
259
|
+
|----------|---------------------|
|
|
260
|
+
| General API errors | Exponential, 3-5 attempts |
|
|
261
|
+
| Rate limiting | Exponential, long initial delay |
|
|
262
|
+
| Timeouts | Linear, medium delays |
|
|
263
|
+
| Flaky network | Constant, short delays |
|
|
264
|
+
| Critical operations | Exponential with high maxAttempts |
|
|
265
|
+
|
|
266
|
+
## Best Practices
|
|
267
|
+
|
|
268
|
+
### Start Small, Increase Gradually
|
|
269
|
+
|
|
270
|
+
```vague
|
|
271
|
+
retry: {
|
|
272
|
+
maxAttempts: 5,
|
|
273
|
+
backoff: exponential,
|
|
274
|
+
initialDelay: 1000, // Start small
|
|
275
|
+
maxDelay: 60000 // Cap at reasonable max
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Be Respectful to APIs
|
|
280
|
+
|
|
281
|
+
```vague
|
|
282
|
+
// Good: respect rate limits
|
|
283
|
+
retry: {
|
|
284
|
+
maxAttempts: 5,
|
|
285
|
+
backoff: exponential,
|
|
286
|
+
initialDelay: 5000
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Risky: aggressive retries
|
|
290
|
+
retry: {
|
|
291
|
+
maxAttempts: 100,
|
|
292
|
+
backoff: constant,
|
|
293
|
+
initialDelay: 100
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Log Retry Attempts
|
|
298
|
+
|
|
299
|
+
```vague
|
|
300
|
+
match response {
|
|
301
|
+
{ code: 503 } -> {
|
|
302
|
+
store {
|
|
303
|
+
event: "retry",
|
|
304
|
+
code: 503,
|
|
305
|
+
timestamp: now()
|
|
306
|
+
} -> retryLog
|
|
307
|
+
retry { maxAttempts: 3 }
|
|
308
|
+
},
|
|
309
|
+
_ -> continue
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Have a Fallback
|
|
314
|
+
|
|
315
|
+
```vague
|
|
316
|
+
match response {
|
|
317
|
+
{ error: _ } -> {
|
|
318
|
+
// After max retries, queue for later
|
|
319
|
+
queue failed { item: { request: currentRequest } }
|
|
320
|
+
skip
|
|
321
|
+
},
|
|
322
|
+
_ -> continue
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Troubleshooting
|
|
327
|
+
|
|
328
|
+
### Retries Not Happening
|
|
329
|
+
|
|
330
|
+
Ensure match directive triggers retry:
|
|
331
|
+
|
|
332
|
+
```vague
|
|
333
|
+
// This triggers retry
|
|
334
|
+
match response {
|
|
335
|
+
{ error: _ } -> retry,
|
|
336
|
+
_ -> continue
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// This does NOT retry
|
|
340
|
+
get "/data" {
|
|
341
|
+
retry: { maxAttempts: 3 } // Only triggers on HTTP errors
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Too Many Retries
|
|
346
|
+
|
|
347
|
+
Lower maxAttempts or add maxDelay:
|
|
348
|
+
|
|
349
|
+
```vague
|
|
350
|
+
retry: {
|
|
351
|
+
maxAttempts: 3,
|
|
352
|
+
maxDelay: 30000
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Retrying Wrong Errors
|
|
357
|
+
|
|
358
|
+
Be specific about which errors to retry:
|
|
359
|
+
|
|
360
|
+
```vague
|
|
361
|
+
match response {
|
|
362
|
+
// Only retry specific codes
|
|
363
|
+
{ code: 429 } -> retry,
|
|
364
|
+
{ code: 503 } -> retry,
|
|
365
|
+
// Don't retry 400, 401, 404, etc.
|
|
366
|
+
_ -> continue
|
|
367
|
+
}
|
|
368
|
+
```
|