@sonamu-kit/tasks 0.1.2 → 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/dist/backend.d.ts +4 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/core/retry.d.ts +35 -19
- package/dist/core/retry.d.ts.map +1 -1
- package/dist/core/retry.js +50 -14
- package/dist/core/retry.js.map +1 -1
- package/dist/core/retry.test.js +172 -11
- package/dist/core/retry.test.js.map +1 -1
- package/dist/database/backend.d.ts.map +1 -1
- package/dist/database/backend.js +114 -5
- package/dist/database/backend.js.map +1 -1
- package/dist/database/backend.testsuite.d.ts.map +1 -1
- package/dist/database/backend.testsuite.js +106 -0
- package/dist/database/backend.testsuite.js.map +1 -1
- package/dist/execution.d.ts +2 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +17 -3
- package/dist/execution.js.map +1 -1
- package/dist/execution.test.js +104 -0
- package/dist/execution.test.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +2 -1
- package/dist/worker.js.map +1 -1
- package/dist/workflow.d.ts +3 -0
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -3
- package/src/backend.ts +4 -0
- package/src/client.ts +2 -0
- package/src/core/retry.test.ts +180 -11
- package/src/core/retry.ts +95 -19
- package/src/database/backend.testsuite.ts +119 -0
- package/src/database/backend.ts +133 -5
- package/src/execution.test.ts +115 -0
- package/src/execution.ts +18 -2
- package/src/internal.ts +21 -1
- package/src/worker.ts +1 -0
- package/src/workflow.ts +3 -0
package/dist/backend.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SerializedError } from "./core/error";
|
|
2
2
|
import type { JsonValue } from "./core/json";
|
|
3
|
+
import type { SerializableRetryPolicy } from "./core/retry";
|
|
3
4
|
import type { StepAttempt, StepAttemptContext, StepKind } from "./core/step";
|
|
4
5
|
import type { WorkflowRun } from "./core/workflow";
|
|
5
6
|
import type { OnSubscribed } from "./database/pubsub";
|
|
@@ -34,6 +35,7 @@ export interface CreateWorkflowRunParams {
|
|
|
34
35
|
input: JsonValue | null;
|
|
35
36
|
availableAt: Date | null;
|
|
36
37
|
deadlineAt: Date | null;
|
|
38
|
+
retryPolicy?: SerializableRetryPolicy;
|
|
37
39
|
}
|
|
38
40
|
export interface GetWorkflowRunParams {
|
|
39
41
|
workflowRunId: string;
|
|
@@ -62,6 +64,8 @@ export interface FailWorkflowRunParams {
|
|
|
62
64
|
workflowRunId: string;
|
|
63
65
|
workerId: string;
|
|
64
66
|
error: SerializedError;
|
|
67
|
+
forceComplete?: boolean;
|
|
68
|
+
customDelayMs?: number;
|
|
65
69
|
}
|
|
66
70
|
export interface CancelWorkflowRunParams {
|
|
67
71
|
workflowRunId: string;
|
package/dist/backend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,OAAO;IAEtB,SAAS,CAAC,QAAQ,EAAE,YAAY,GA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IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH"}
|
package/dist/backend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/backend.ts"],"sourcesContent":["import type { SerializedError } from \"./core/error\";\nimport type { JsonValue } from \"./core/json\";\nimport type { StepAttempt, StepAttemptContext, StepKind } from \"./core/step\";\nimport type { WorkflowRun } from \"./core/workflow\";\nimport type { OnSubscribed } from \"./database/pubsub\";\n\nexport const DEFAULT_NAMESPACE_ID = \"default\";\n\n/**\n * Backend is the interface for backend providers to implement.\n */\nexport interface Backend {\n // Listen for events on a channel\n subscribe(callback: OnSubscribed): Promise<void>;\n publish(payload?: string): Promise<void>;\n\n // Workflow Runs\n createWorkflowRun(params: Readonly<CreateWorkflowRunParams>): Promise<WorkflowRun>;\n getWorkflowRun(params: Readonly<GetWorkflowRunParams>): Promise<WorkflowRun | null>;\n listWorkflowRuns(\n params: Readonly<ListWorkflowRunsParams>,\n ): Promise<PaginatedResponse<WorkflowRun>>;\n claimWorkflowRun(params: Readonly<ClaimWorkflowRunParams>): Promise<WorkflowRun | null>;\n extendWorkflowRunLease(params: Readonly<ExtendWorkflowRunLeaseParams>): Promise<WorkflowRun>;\n sleepWorkflowRun(params: Readonly<SleepWorkflowRunParams>): Promise<WorkflowRun>;\n completeWorkflowRun(params: Readonly<CompleteWorkflowRunParams>): Promise<WorkflowRun>;\n failWorkflowRun(params: Readonly<FailWorkflowRunParams>): Promise<WorkflowRun>;\n cancelWorkflowRun(params: Readonly<CancelWorkflowRunParams>): Promise<WorkflowRun>;\n\n // Step Attempts\n createStepAttempt(params: Readonly<CreateStepAttemptParams>): Promise<StepAttempt>;\n getStepAttempt(params: Readonly<GetStepAttemptParams>): Promise<StepAttempt | null>;\n listStepAttempts(\n params: Readonly<ListStepAttemptsParams>,\n ): Promise<PaginatedResponse<StepAttempt>>;\n completeStepAttempt(params: Readonly<CompleteStepAttemptParams>): Promise<StepAttempt>;\n failStepAttempt(params: Readonly<FailStepAttemptParams>): Promise<StepAttempt>;\n}\n\nexport interface CreateWorkflowRunParams {\n workflowName: string;\n version: string | null;\n idempotencyKey: string | null;\n config: JsonValue;\n context: JsonValue | null;\n input: JsonValue | null;\n availableAt: Date | null; // null = immediately\n deadlineAt: Date | null; // null = no deadline\n}\n\nexport interface GetWorkflowRunParams {\n workflowRunId: string;\n}\n\nexport type ListWorkflowRunsParams = PaginationOptions;\n\nexport interface ClaimWorkflowRunParams {\n workerId: string;\n leaseDurationMs: number;\n}\n\nexport interface ExtendWorkflowRunLeaseParams {\n workflowRunId: string;\n workerId: string;\n leaseDurationMs: number;\n}\n\nexport interface SleepWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n availableAt: Date;\n}\n\nexport interface CompleteWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n output: JsonValue | null;\n}\n\nexport interface FailWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n error: SerializedError;\n}\n\nexport interface CancelWorkflowRunParams {\n workflowRunId: string;\n}\n\nexport interface CreateStepAttemptParams {\n workflowRunId: string;\n workerId: string;\n stepName: string;\n kind: StepKind;\n config: JsonValue;\n context: StepAttemptContext | null;\n}\n\nexport interface GetStepAttemptParams {\n stepAttemptId: string;\n}\n\nexport interface ListStepAttemptsParams extends PaginationOptions {\n workflowRunId: string;\n}\n\nexport interface CompleteStepAttemptParams {\n workflowRunId: string;\n stepAttemptId: string;\n workerId: string;\n output: JsonValue | null;\n}\n\nexport interface FailStepAttemptParams {\n workflowRunId: string;\n stepAttemptId: string;\n workerId: string;\n error: SerializedError;\n}\n\nexport interface PaginationOptions {\n limit?: number;\n after?: string;\n before?: string;\n}\n\nexport interface PaginatedResponse<T> {\n data: T[];\n pagination: {\n next: string | null;\n prev: string | null;\n };\n}\n"],"names":["DEFAULT_NAMESPACE_ID"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/backend.ts"],"sourcesContent":["import type { SerializedError } from \"./core/error\";\nimport type { JsonValue } from \"./core/json\";\nimport type { SerializableRetryPolicy } from \"./core/retry\";\nimport type { StepAttempt, StepAttemptContext, StepKind } from \"./core/step\";\nimport type { WorkflowRun } from \"./core/workflow\";\nimport type { OnSubscribed } from \"./database/pubsub\";\n\nexport const DEFAULT_NAMESPACE_ID = \"default\";\n\n/**\n * Backend is the interface for backend providers to implement.\n */\nexport interface Backend {\n // Listen for events on a channel\n subscribe(callback: OnSubscribed): Promise<void>;\n publish(payload?: string): Promise<void>;\n\n // Workflow Runs\n createWorkflowRun(params: Readonly<CreateWorkflowRunParams>): Promise<WorkflowRun>;\n getWorkflowRun(params: Readonly<GetWorkflowRunParams>): Promise<WorkflowRun | null>;\n listWorkflowRuns(\n params: Readonly<ListWorkflowRunsParams>,\n ): Promise<PaginatedResponse<WorkflowRun>>;\n claimWorkflowRun(params: Readonly<ClaimWorkflowRunParams>): Promise<WorkflowRun | null>;\n extendWorkflowRunLease(params: Readonly<ExtendWorkflowRunLeaseParams>): Promise<WorkflowRun>;\n sleepWorkflowRun(params: Readonly<SleepWorkflowRunParams>): Promise<WorkflowRun>;\n completeWorkflowRun(params: Readonly<CompleteWorkflowRunParams>): Promise<WorkflowRun>;\n failWorkflowRun(params: Readonly<FailWorkflowRunParams>): Promise<WorkflowRun>;\n cancelWorkflowRun(params: Readonly<CancelWorkflowRunParams>): Promise<WorkflowRun>;\n\n // Step Attempts\n createStepAttempt(params: Readonly<CreateStepAttemptParams>): Promise<StepAttempt>;\n getStepAttempt(params: Readonly<GetStepAttemptParams>): Promise<StepAttempt | null>;\n listStepAttempts(\n params: Readonly<ListStepAttemptsParams>,\n ): Promise<PaginatedResponse<StepAttempt>>;\n completeStepAttempt(params: Readonly<CompleteStepAttemptParams>): Promise<StepAttempt>;\n failStepAttempt(params: Readonly<FailStepAttemptParams>): Promise<StepAttempt>;\n}\n\nexport interface CreateWorkflowRunParams {\n workflowName: string;\n version: string | null;\n idempotencyKey: string | null;\n config: JsonValue;\n context: JsonValue | null;\n input: JsonValue | null;\n availableAt: Date | null; // null = immediately\n deadlineAt: Date | null; // null = no deadline\n retryPolicy?: SerializableRetryPolicy;\n}\n\nexport interface GetWorkflowRunParams {\n workflowRunId: string;\n}\n\nexport type ListWorkflowRunsParams = PaginationOptions;\n\nexport interface ClaimWorkflowRunParams {\n workerId: string;\n leaseDurationMs: number;\n}\n\nexport interface ExtendWorkflowRunLeaseParams {\n workflowRunId: string;\n workerId: string;\n leaseDurationMs: number;\n}\n\nexport interface SleepWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n availableAt: Date;\n}\n\nexport interface CompleteWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n output: JsonValue | null;\n}\n\nexport interface FailWorkflowRunParams {\n workflowRunId: string;\n workerId: string;\n error: SerializedError;\n forceComplete?: boolean;\n customDelayMs?: number;\n}\n\nexport interface CancelWorkflowRunParams {\n workflowRunId: string;\n}\n\nexport interface CreateStepAttemptParams {\n workflowRunId: string;\n workerId: string;\n stepName: string;\n kind: StepKind;\n config: JsonValue;\n context: StepAttemptContext | null;\n}\n\nexport interface GetStepAttemptParams {\n stepAttemptId: string;\n}\n\nexport interface ListStepAttemptsParams extends PaginationOptions {\n workflowRunId: string;\n}\n\nexport interface CompleteStepAttemptParams {\n workflowRunId: string;\n stepAttemptId: string;\n workerId: string;\n output: JsonValue | null;\n}\n\nexport interface FailStepAttemptParams {\n workflowRunId: string;\n stepAttemptId: string;\n workerId: string;\n error: SerializedError;\n}\n\nexport interface PaginationOptions {\n limit?: number;\n after?: string;\n before?: string;\n}\n\nexport interface PaginatedResponse<T> {\n data: T[];\n pagination: {\n next: string | null;\n prev: string | null;\n };\n}\n"],"names":["DEFAULT_NAMESPACE_ID"],"mappings":"AAOA,OAAO,MAAMA,uBAAuB,UAAU"}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KA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QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAEzC,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC;IAKzE;;;;;OAKG;IACG,GAAG,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAG9F;AAMD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;IAElB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,MAAM;IACnC,OAAO,CAAC,OAAO,CAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,eAAe,CAAS;gBAEpB,OAAO,EAAE,qBAAqB;IAO1C;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAsC/B;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serializeRetryPolicy } from "./core/retry.js";
|
|
1
2
|
import { validateInput } from "./core/workflow.js";
|
|
2
3
|
import { WorkflowRegistry } from "./registry.js";
|
|
3
4
|
import { Worker } from "./worker.js";
|
|
@@ -65,7 +66,8 @@ const DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m
|
|
|
65
66
|
context: null,
|
|
66
67
|
input: parsedInput ?? null,
|
|
67
68
|
availableAt: null,
|
|
68
|
-
deadlineAt: options?.deadlineAt ?? null
|
|
69
|
+
deadlineAt: options?.deadlineAt ?? null,
|
|
70
|
+
retryPolicy: spec.retryPolicy ? serializeRetryPolicy(spec.retryPolicy) : undefined
|
|
69
71
|
});
|
|
70
72
|
if (options?.publishToChannel) {
|
|
71
73
|
await this.backend.publish(workflowRun.id);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Backend } from \"./backend\";\nimport type { StandardSchemaV1 } from \"./core/schema\";\nimport type { SchemaInput, SchemaOutput, WorkflowRun } from \"./core/workflow\";\nimport { validateInput } from \"./core/workflow\";\nimport type { WorkflowFunction } from \"./execution\";\nimport { WorkflowRegistry } from \"./registry\";\nimport { Worker, type WorkerOptions } from \"./worker\";\nimport { defineWorkflow, defineWorkflowSpec, type Workflow, type WorkflowSpec } from \"./workflow\";\n\nconst DEFAULT_RESULT_POLL_INTERVAL_MS = 1000; // 1s\nconst DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m\n\n/* The data the worker function receives (after transformation). */\ntype WorkflowHandlerInput<TSchema, Input> = SchemaOutput<TSchema, Input>;\n\n/* The data the client sends (before transformation) */\ntype WorkflowRunInput<TSchema, Input> = SchemaInput<TSchema, Input>;\n\n/**\n * Options for the OpenWorkflow client.\n */\nexport interface OpenWorkflowOptions {\n backend: Backend;\n}\n\n/**\n * Client used to register workflows and start runs.\n */\nexport class OpenWorkflow {\n private backend: Backend;\n private registry = new WorkflowRegistry();\n\n constructor(options: OpenWorkflowOptions) {\n this.backend = options.backend;\n }\n\n /**\n * Create a new Worker with this client's backend and workflows.\n * @param options - Worker options\n * @param options.concurrency - Max concurrent workflow runs\n * @returns Worker instance\n */\n newWorker(options?: {\n concurrency?: number | undefined;\n usePubSub?: boolean;\n listenDelay?: number;\n }): Worker {\n return new Worker({\n backend: this.backend,\n registry: this.registry,\n concurrency: options?.concurrency,\n usePubSub: options?.usePubSub,\n listenDelay: options?.listenDelay,\n } satisfies WorkerOptions);\n }\n\n /**\n * Provide the implementation for a declared workflow. This links the workflow\n * specification to its execution logic and registers it with this\n * OpenWorkflow instance for worker execution.\n * @param spec - Workflow spec\n * @param fn - Workflow implementation\n */\n implementWorkflow<Input, Output, RunInput = Input>(\n spec: WorkflowSpec<Input, Output, RunInput>,\n fn: WorkflowFunction<Input, Output>,\n ): void {\n const workflow: Workflow<Input, Output, RunInput> = { spec, fn };\n this.registry.register(workflow as Workflow<unknown, unknown, unknown>);\n }\n\n /**\n * Run a workflow from its specification. This is the primary way to schedule\n * a workflow using only its WorkflowSpec.\n * @param spec - Workflow spec\n * @param input - Workflow input\n * @param options - Run options\n * @returns Handle for awaiting the result\n * @example\n * ```ts\n * const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });\n * const result = await handle.result();\n * ```\n */\n async runWorkflow<Input, Output, RunInput = Input>(\n spec: WorkflowSpec<Input, Output, RunInput>,\n input?: RunInput,\n options?: WorkflowRunOptions,\n ): Promise<WorkflowRunHandle<Output>> {\n const validationResult = await validateInput(spec.schema, input);\n if (!validationResult.success) {\n throw new Error(validationResult.error);\n }\n const parsedInput = validationResult.value;\n const workflowRun = await this.backend.createWorkflowRun({\n workflowName: spec.name,\n version: spec.version ?? null,\n idempotencyKey: null,\n config: {},\n context: null,\n input: parsedInput ?? null,\n availableAt: null,\n deadlineAt: options?.deadlineAt ?? null,\n });\n\n if (options?.publishToChannel) {\n await this.backend.publish(workflowRun.id);\n }\n\n return new WorkflowRunHandle<Output>({\n backend: this.backend,\n workflowRun: workflowRun,\n resultPollIntervalMs: DEFAULT_RESULT_POLL_INTERVAL_MS,\n resultTimeoutMs: DEFAULT_RESULT_TIMEOUT_MS,\n });\n }\n\n /**\n * Define and register a new workflow.\n *\n * This is a convenience method that combines `declareWorkflow` and\n * `implementWorkflow` into a single call. For better code splitting and to\n * separate declaration from implementation, consider using those methods\n * separately.\n * @param config - Workflow config\n * @param fn - Workflow implementation\n * @returns Runnable workflow\n * @example\n * ```ts\n * const workflow = ow.defineWorkflow(\n * { name: 'my-workflow' },\n * async ({ input, step }) => {\n * // workflow implementation\n * },\n * );\n * ```\n */\n defineWorkflow<Input, Output, TSchema extends StandardSchemaV1 | undefined = undefined>(\n spec: WorkflowSpec<\n WorkflowHandlerInput<TSchema, Input>,\n Output,\n WorkflowRunInput<TSchema, Input>\n >,\n fn: WorkflowFunction<WorkflowHandlerInput<TSchema, Input>, Output>,\n ): RunnableWorkflow<\n WorkflowHandlerInput<TSchema, Input>,\n Output,\n WorkflowRunInput<TSchema, Input>\n > {\n const workflow = defineWorkflow(spec, fn);\n this.registry.register(workflow as Workflow<unknown, unknown, unknown>);\n return new RunnableWorkflow(this, workflow);\n }\n\n /**\n * Unregister a workflow from the registry.\n * @param name - The workflow name\n * @param version - The workflow version (null for unversioned)\n * @example\n * ```ts\n * ow.unregisterWorkflow(\"my-workflow\", \"v1\");\n * ```\n */\n unregisterWorkflow(name: string, version: string | null): void {\n this.registry.remove(name, version);\n }\n\n /**\n * Check if a workflow is registered in the registry.\n * @param name - The workflow name\n * @param version - The workflow version (null for unversioned)\n * @returns True if the workflow is registered, false otherwise\n * @example\n * ```ts\n * ow.isWorkflowRegistered(\"my-workflow\", \"v1\");\n * ```\n */\n isWorkflowRegistered(name: string, version: string | null): boolean {\n return this.registry.has(name, version);\n }\n}\n\n/**\n * Declare a workflow without providing its implementation (which is provided\n * separately via `implementWorkflow`). Returns a lightweight WorkflowSpec\n * that can be used to schedule workflow runs.\n * @param spec - Workflow spec\n * @returns Workflow spec\n * @example\n * ```ts\n * export const emailWorkflow = declareWorkflow({\n * name: 'send-email',\n * schema: z.object({ to: z.string().email() }),\n * });\n * ```\n */\n// kept for backwards compatibility, to be deprecated\n// eslint-disable-next-line unicorn/prefer-export-from\nexport const declareWorkflow = defineWorkflowSpec;\n\n//\n// --- Workflow Definition\n//\n\n/**\n * A fully defined workflow with its implementation. This class is returned by\n * `defineWorkflow` and provides the `.run()` method for scheduling workflow\n * runs.\n */\nexport class RunnableWorkflow<Input, Output, RunInput = Input> {\n private readonly ow: OpenWorkflow;\n readonly workflow: Workflow<Input, Output, RunInput>;\n\n constructor(ow: OpenWorkflow, workflow: Workflow<Input, Output, RunInput>) {\n this.ow = ow;\n this.workflow = workflow;\n }\n\n /**\n * Starts a new workflow run.\n * @param input - Workflow input\n * @param options - Run options\n * @returns Workflow run handle\n */\n async run(input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>> {\n return this.ow.runWorkflow(this.workflow.spec, input, options);\n }\n}\n\n//\n// --- Workflow Run\n//\n\n/**\n * Options for creating a new workflow run from a runnable workflow when calling\n * `workflow.run()`.\n */\nexport interface WorkflowRunOptions {\n /**\n * Set a deadline for the workflow run. If the workflow exceeds this deadline,\n * it will be marked as failed.\n */\n deadlineAt?: Date;\n\n /**\n * Publish when the workflow run is created to the channel.\n * Default: true\n */\n publishToChannel?: boolean;\n}\n\n/**\n * Options for WorkflowHandle.\n */\nexport interface WorkflowHandleOptions {\n backend: Backend;\n workflowRun: WorkflowRun;\n resultPollIntervalMs: number;\n resultTimeoutMs: number;\n}\n\n/**\n * Represents a started workflow run and provides methods to await its result.\n * Returned from `workflowDef.run()`.\n */\nexport class WorkflowRunHandle<Output> {\n private backend: Backend;\n readonly workflowRun: WorkflowRun;\n private resultPollIntervalMs: number;\n private resultTimeoutMs: number;\n\n constructor(options: WorkflowHandleOptions) {\n this.backend = options.backend;\n this.workflowRun = options.workflowRun;\n this.resultPollIntervalMs = options.resultPollIntervalMs;\n this.resultTimeoutMs = options.resultTimeoutMs;\n }\n\n /**\n * Waits for the workflow run to complete and returns the result.\n * @returns Workflow output\n */\n async result(): Promise<Output> {\n const start = Date.now();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const latest = await this.backend.getWorkflowRun({\n workflowRunId: this.workflowRun.id,\n });\n\n if (!latest) {\n throw new Error(`Workflow run ${this.workflowRun.id} no longer exists`);\n }\n\n // 'succeeded' status is deprecated\n if (latest.status === \"succeeded\" || latest.status === \"completed\") {\n return latest.output as Output;\n }\n\n if (latest.status === \"failed\") {\n throw new Error(\n `Workflow ${this.workflowRun.workflowName} failed: ${JSON.stringify(latest.error)}`,\n );\n }\n\n if (latest.status === \"canceled\") {\n throw new Error(`Workflow ${this.workflowRun.workflowName} was canceled`);\n }\n\n if (Date.now() - start > this.resultTimeoutMs) {\n throw new Error(`Timed out waiting for workflow run ${this.workflowRun.id} to finish`);\n }\n\n await new Promise((resolve) => {\n setTimeout(resolve, this.resultPollIntervalMs);\n });\n }\n }\n\n /**\n * Cancels the workflow run. Only workflows in pending, running, or sleeping\n * status can be canceled.\n */\n async cancel(): Promise<void> {\n await this.backend.cancelWorkflowRun({\n workflowRunId: this.workflowRun.id,\n });\n }\n}\n"],"names":["validateInput","WorkflowRegistry","Worker","defineWorkflow","defineWorkflowSpec","DEFAULT_RESULT_POLL_INTERVAL_MS","DEFAULT_RESULT_TIMEOUT_MS","OpenWorkflow","backend","registry","options","newWorker","concurrency","usePubSub","listenDelay","implementWorkflow","spec","fn","workflow","register","runWorkflow","input","validationResult","schema","success","Error","error","parsedInput","value","workflowRun","createWorkflowRun","workflowName","name","version","idempotencyKey","config","context","availableAt","deadlineAt","publishToChannel","publish","id","WorkflowRunHandle","resultPollIntervalMs","resultTimeoutMs","RunnableWorkflow","unregisterWorkflow","remove","isWorkflowRegistered","has","declareWorkflow","ow","run","result","start","Date","now","latest","getWorkflowRun","workflowRunId","status","output","JSON","stringify","Promise","resolve","setTimeout","cancel","cancelWorkflowRun"],"mappings":"AAGA,SAASA,aAAa,QAAQ,qBAAkB;AAEhD,SAASC,gBAAgB,QAAQ,gBAAa;AAC9C,SAASC,MAAM,QAA4B,cAAW;AACtD,SAASC,cAAc,EAAEC,kBAAkB,QAA0C,gBAAa;AA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,IAAI,CAAC3D,OAAO,CAAC4D,iBAAiB,CAAC;YACnCT,eAAe,IAAI,CAAC9B,WAAW,CAACY,EAAE;QACpC;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Backend } from \"./backend\";\nimport { serializeRetryPolicy } from \"./core/retry\";\nimport type { StandardSchemaV1 } from \"./core/schema\";\nimport type { SchemaInput, SchemaOutput, WorkflowRun } from \"./core/workflow\";\nimport { validateInput } from \"./core/workflow\";\nimport type { WorkflowFunction } from \"./execution\";\nimport { WorkflowRegistry } from \"./registry\";\nimport { Worker, type WorkerOptions } from \"./worker\";\nimport { defineWorkflow, defineWorkflowSpec, type Workflow, type WorkflowSpec } from \"./workflow\";\n\nconst DEFAULT_RESULT_POLL_INTERVAL_MS = 1000; // 1s\nconst DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m\n\n/* The data the worker function receives (after transformation). */\ntype WorkflowHandlerInput<TSchema, Input> = SchemaOutput<TSchema, Input>;\n\n/* The data the client sends (before transformation) */\ntype WorkflowRunInput<TSchema, Input> = SchemaInput<TSchema, Input>;\n\n/**\n * Options for the OpenWorkflow client.\n */\nexport interface OpenWorkflowOptions {\n backend: Backend;\n}\n\n/**\n * Client used to register workflows and start runs.\n */\nexport class OpenWorkflow {\n private backend: Backend;\n private registry = new WorkflowRegistry();\n\n constructor(options: OpenWorkflowOptions) {\n this.backend = options.backend;\n }\n\n /**\n * Create a new Worker with this client's backend and workflows.\n * @param options - Worker options\n * @param options.concurrency - Max concurrent workflow runs\n * @returns Worker instance\n */\n newWorker(options?: {\n concurrency?: number | undefined;\n usePubSub?: boolean;\n listenDelay?: number;\n }): Worker {\n return new Worker({\n backend: this.backend,\n registry: this.registry,\n concurrency: options?.concurrency,\n usePubSub: options?.usePubSub,\n listenDelay: options?.listenDelay,\n } satisfies WorkerOptions);\n }\n\n /**\n * Provide the implementation for a declared workflow. This links the workflow\n * specification to its execution logic and registers it with this\n * OpenWorkflow instance for worker execution.\n * @param spec - Workflow spec\n * @param fn - Workflow implementation\n */\n implementWorkflow<Input, Output, RunInput = Input>(\n spec: WorkflowSpec<Input, Output, RunInput>,\n fn: WorkflowFunction<Input, Output>,\n ): void {\n const workflow: Workflow<Input, Output, RunInput> = { spec, fn };\n this.registry.register(workflow as Workflow<unknown, unknown, unknown>);\n }\n\n /**\n * Run a workflow from its specification. This is the primary way to schedule\n * a workflow using only its WorkflowSpec.\n * @param spec - Workflow spec\n * @param input - Workflow input\n * @param options - Run options\n * @returns Handle for awaiting the result\n * @example\n * ```ts\n * const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });\n * const result = await handle.result();\n * ```\n */\n async runWorkflow<Input, Output, RunInput = Input>(\n spec: WorkflowSpec<Input, Output, RunInput>,\n input?: RunInput,\n options?: WorkflowRunOptions,\n ): Promise<WorkflowRunHandle<Output>> {\n const validationResult = await validateInput(spec.schema, input);\n if (!validationResult.success) {\n throw new Error(validationResult.error);\n }\n const parsedInput = validationResult.value;\n const workflowRun = await this.backend.createWorkflowRun({\n workflowName: spec.name,\n version: spec.version ?? null,\n idempotencyKey: null,\n config: {},\n context: null,\n input: parsedInput ?? null,\n availableAt: null,\n deadlineAt: options?.deadlineAt ?? null,\n retryPolicy: spec.retryPolicy ? serializeRetryPolicy(spec.retryPolicy) : undefined,\n });\n\n if (options?.publishToChannel) {\n await this.backend.publish(workflowRun.id);\n }\n\n return new WorkflowRunHandle<Output>({\n backend: this.backend,\n workflowRun: workflowRun,\n resultPollIntervalMs: DEFAULT_RESULT_POLL_INTERVAL_MS,\n resultTimeoutMs: DEFAULT_RESULT_TIMEOUT_MS,\n });\n }\n\n /**\n * Define and register a new workflow.\n *\n * This is a convenience method that combines `declareWorkflow` and\n * `implementWorkflow` into a single call. For better code splitting and to\n * separate declaration from implementation, consider using those methods\n * separately.\n * @param config - Workflow config\n * @param fn - Workflow implementation\n * @returns Runnable workflow\n * @example\n * ```ts\n * const workflow = ow.defineWorkflow(\n * { name: 'my-workflow' },\n * async ({ input, step }) => {\n * // workflow implementation\n * },\n * );\n * ```\n */\n defineWorkflow<Input, Output, TSchema extends StandardSchemaV1 | undefined = undefined>(\n spec: WorkflowSpec<\n WorkflowHandlerInput<TSchema, Input>,\n Output,\n WorkflowRunInput<TSchema, Input>\n >,\n fn: WorkflowFunction<WorkflowHandlerInput<TSchema, Input>, Output>,\n ): RunnableWorkflow<\n WorkflowHandlerInput<TSchema, Input>,\n Output,\n WorkflowRunInput<TSchema, Input>\n > {\n const workflow = defineWorkflow(spec, fn);\n this.registry.register(workflow as Workflow<unknown, unknown, unknown>);\n return new RunnableWorkflow(this, workflow);\n }\n\n /**\n * Unregister a workflow from the registry.\n * @param name - The workflow name\n * @param version - The workflow version (null for unversioned)\n * @example\n * ```ts\n * ow.unregisterWorkflow(\"my-workflow\", \"v1\");\n * ```\n */\n unregisterWorkflow(name: string, version: string | null): void {\n this.registry.remove(name, version);\n }\n\n /**\n * Check if a workflow is registered in the registry.\n * @param name - The workflow name\n * @param version - The workflow version (null for unversioned)\n * @returns True if the workflow is registered, false otherwise\n * @example\n * ```ts\n * ow.isWorkflowRegistered(\"my-workflow\", \"v1\");\n * ```\n */\n isWorkflowRegistered(name: string, version: string | null): boolean {\n return this.registry.has(name, version);\n }\n}\n\n/**\n * Declare a workflow without providing its implementation (which is provided\n * separately via `implementWorkflow`). Returns a lightweight WorkflowSpec\n * that can be used to schedule workflow runs.\n * @param spec - Workflow spec\n * @returns Workflow spec\n * @example\n * ```ts\n * export const emailWorkflow = declareWorkflow({\n * name: 'send-email',\n * schema: z.object({ to: z.string().email() }),\n * });\n * ```\n */\n// kept for backwards compatibility, to be deprecated\n// eslint-disable-next-line unicorn/prefer-export-from\nexport const declareWorkflow = defineWorkflowSpec;\n\n//\n// --- Workflow Definition\n//\n\n/**\n * A fully defined workflow with its implementation. This class is returned by\n * `defineWorkflow` and provides the `.run()` method for scheduling workflow\n * runs.\n */\nexport class RunnableWorkflow<Input, Output, RunInput = Input> {\n private readonly ow: OpenWorkflow;\n readonly workflow: Workflow<Input, Output, RunInput>;\n\n constructor(ow: OpenWorkflow, workflow: Workflow<Input, Output, RunInput>) {\n this.ow = ow;\n this.workflow = workflow;\n }\n\n /**\n * Starts a new workflow run.\n * @param input - Workflow input\n * @param options - Run options\n * @returns Workflow run handle\n */\n async run(input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>> {\n return this.ow.runWorkflow(this.workflow.spec, input, options);\n }\n}\n\n//\n// --- Workflow Run\n//\n\n/**\n * Options for creating a new workflow run from a runnable workflow when calling\n * `workflow.run()`.\n */\nexport interface WorkflowRunOptions {\n /**\n * Set a deadline for the workflow run. If the workflow exceeds this deadline,\n * it will be marked as failed.\n */\n deadlineAt?: Date;\n\n /**\n * Publish when the workflow run is created to the channel.\n * Default: true\n */\n publishToChannel?: boolean;\n}\n\n/**\n * Options for WorkflowHandle.\n */\nexport interface WorkflowHandleOptions {\n backend: Backend;\n workflowRun: WorkflowRun;\n resultPollIntervalMs: number;\n resultTimeoutMs: number;\n}\n\n/**\n * Represents a started workflow run and provides methods to await its result.\n * Returned from `workflowDef.run()`.\n */\nexport class WorkflowRunHandle<Output> {\n private backend: Backend;\n readonly workflowRun: WorkflowRun;\n private resultPollIntervalMs: number;\n private resultTimeoutMs: number;\n\n constructor(options: WorkflowHandleOptions) {\n this.backend = options.backend;\n this.workflowRun = options.workflowRun;\n this.resultPollIntervalMs = options.resultPollIntervalMs;\n this.resultTimeoutMs = options.resultTimeoutMs;\n }\n\n /**\n * Waits for the workflow run to complete and returns the result.\n * @returns Workflow output\n */\n async result(): Promise<Output> {\n const start = Date.now();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const latest = await this.backend.getWorkflowRun({\n workflowRunId: this.workflowRun.id,\n });\n\n if (!latest) {\n throw new Error(`Workflow run ${this.workflowRun.id} no longer exists`);\n }\n\n // 'succeeded' status is deprecated\n if (latest.status === \"succeeded\" || latest.status === \"completed\") {\n return latest.output as Output;\n }\n\n if (latest.status === \"failed\") {\n throw new Error(\n `Workflow ${this.workflowRun.workflowName} failed: ${JSON.stringify(latest.error)}`,\n );\n }\n\n if (latest.status === \"canceled\") {\n throw new Error(`Workflow ${this.workflowRun.workflowName} was canceled`);\n }\n\n if (Date.now() - start > this.resultTimeoutMs) {\n throw new Error(`Timed out waiting for workflow run ${this.workflowRun.id} to finish`);\n }\n\n await new Promise((resolve) => {\n setTimeout(resolve, this.resultPollIntervalMs);\n });\n }\n }\n\n /**\n * Cancels the workflow run. Only workflows in pending, running, or sleeping\n * status can be canceled.\n */\n async cancel(): Promise<void> {\n await this.backend.cancelWorkflowRun({\n workflowRunId: this.workflowRun.id,\n });\n }\n}\n"],"names":["serializeRetryPolicy","validateInput","WorkflowRegistry","Worker","defineWorkflow","defineWorkflowSpec","DEFAULT_RESULT_POLL_INTERVAL_MS","DEFAULT_RESULT_TIMEOUT_MS","OpenWorkflow","backend","registry","options","newWorker","concurrency","usePubSub","listenDelay","implementWorkflow","spec","fn","workflow","register","runWorkflow","input","validationResult","schema","success","Error","error","parsedInput","value","workflowRun","createWorkflowRun","workflowName","name","version","idempotencyKey","config","context","availableAt","deadlineAt","retryPolicy","undefined","publishToChannel","publish","id","WorkflowRunHandle","resultPollIntervalMs","resultTimeoutMs","RunnableWorkflow","unregisterWorkflow","remove","isWorkflowRegistered","has","declareWorkflow","ow","run","result","start","Date","now","latest","getWorkflowRun","workflowRunId","status","output","JSON","stringify","Promise","resolve","setTimeout","cancel","cancelWorkflowRun"],"mappings":"AACA,SAASA,oBAAoB,QAAQ,kBAAe;AAGpD,SAASC,aAAa,QAAQ,qBAAkB;AAEhD,SAASC,gBAAgB,QAAQ,gBAAa;AAC9C,SAASC,MAAM,QAA4B,cAAW;AACtD,SAASC,cAAc,EAAEC,kBAAkB,QAA0C,gBAAa;AAElG,MAAMC,kCAAkC,MAAM,KAAK;AACnD,MAAMC,4BAA4B,IAAI,KAAK,MAA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AC5B,MAAM,IAAI,CAAC7D,OAAO,CAAC8D,iBAAiB,CAAC;YACnCT,eAAe,IAAI,CAAChC,WAAW,CAACc,EAAE;QACpC;IACF;AACF"}
|
package/dist/core/retry.d.ts
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { SerializedError } from "./error";
|
|
2
|
+
export interface RetryDecision {
|
|
3
|
+
shouldRetry: boolean;
|
|
4
|
+
delayMs: number;
|
|
5
|
+
}
|
|
6
|
+
export type RetryDecisionFn = (error: SerializedError, attempt: number) => RetryDecision;
|
|
7
|
+
export interface StaticRetryPolicy {
|
|
8
|
+
maxAttempts?: number;
|
|
9
|
+
initialIntervalMs?: number;
|
|
10
|
+
backoffCoefficient?: number;
|
|
11
|
+
maximumIntervalMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface DynamicRetryPolicy {
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
shouldRetry: RetryDecisionFn;
|
|
16
|
+
}
|
|
17
|
+
export type RetryPolicy = StaticRetryPolicy | DynamicRetryPolicy;
|
|
18
|
+
export interface SerializableRetryPolicy extends StaticRetryPolicy {
|
|
19
|
+
hasDynamicPolicy?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type MergedStaticRetryPolicy = Required<StaticRetryPolicy>;
|
|
22
|
+
export interface MergedDynamicRetryPolicy {
|
|
23
|
+
maxAttempts: number;
|
|
24
|
+
shouldRetry: RetryDecisionFn;
|
|
25
|
+
}
|
|
26
|
+
export type MergedRetryPolicy = MergedStaticRetryPolicy | MergedDynamicRetryPolicy;
|
|
27
|
+
export declare const DEFAULT_RETRY_POLICY: Required<StaticRetryPolicy>;
|
|
28
|
+
export declare function isDynamicRetryPolicy(policy: RetryPolicy): policy is DynamicRetryPolicy;
|
|
29
|
+
export declare function isStaticRetryPolicy(policy: RetryPolicy): policy is StaticRetryPolicy;
|
|
13
30
|
export declare function calculateRetryDelayMs(attemptNumber: number): number;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare function shouldRetry(retryPolicy: RetryPolicy, attemptNumber: number): boolean;
|
|
31
|
+
export declare function shouldRetry(retryPolicy: StaticRetryPolicy, attemptNumber: number): boolean;
|
|
32
|
+
export declare function shouldRetryByPolicy(policy: StaticRetryPolicy, attemptNumber: number): boolean;
|
|
33
|
+
export declare function mergeRetryPolicy(policy: StaticRetryPolicy | undefined): MergedStaticRetryPolicy;
|
|
34
|
+
export declare function mergeRetryPolicy(policy: DynamicRetryPolicy): MergedDynamicRetryPolicy;
|
|
35
|
+
export declare function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy;
|
|
36
|
+
export declare function serializeRetryPolicy(policy?: RetryPolicy): SerializableRetryPolicy;
|
|
21
37
|
//# sourceMappingURL=retry.d.ts.map
|
package/dist/core/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/core/retry.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/core/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,KAAK,aAAa,CAAC;AAEzF,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,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B,CAAC;AAgB1E,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,uBAAuB,CAmBlF"}
|
package/dist/core/retry.js
CHANGED
|
@@ -1,25 +1,61 @@
|
|
|
1
1
|
export const DEFAULT_RETRY_POLICY = {
|
|
2
|
+
maxAttempts: 5,
|
|
2
3
|
initialIntervalMs: 1000,
|
|
3
4
|
backoffCoefficient: 2,
|
|
4
|
-
maximumIntervalMs:
|
|
5
|
-
maximumAttempts: Infinity
|
|
5
|
+
maximumIntervalMs: 60_000
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export function isDynamicRetryPolicy(policy) {
|
|
8
|
+
return "shouldRetry" in policy && typeof policy.shouldRetry === "function";
|
|
9
|
+
}
|
|
10
|
+
export function isStaticRetryPolicy(policy) {
|
|
11
|
+
return !isDynamicRetryPolicy(policy);
|
|
12
|
+
}
|
|
13
|
+
export function calculateRetryDelayMs(attemptNumber) {
|
|
12
14
|
const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;
|
|
13
15
|
const backoffMs = initialIntervalMs * backoffCoefficient ** (attemptNumber - 1);
|
|
14
16
|
return Math.min(backoffMs, maximumIntervalMs);
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return attemptNumber <
|
|
18
|
+
export function shouldRetry(retryPolicy, attemptNumber) {
|
|
19
|
+
const maxAttempts = retryPolicy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;
|
|
20
|
+
return attemptNumber < maxAttempts;
|
|
21
|
+
}
|
|
22
|
+
export function shouldRetryByPolicy(policy, attemptNumber) {
|
|
23
|
+
const maxAttempts = policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;
|
|
24
|
+
return attemptNumber < maxAttempts;
|
|
25
|
+
}
|
|
26
|
+
export function mergeRetryPolicy(policy) {
|
|
27
|
+
if (policy && isDynamicRetryPolicy(policy)) {
|
|
28
|
+
return {
|
|
29
|
+
maxAttempts: policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,
|
|
30
|
+
shouldRetry: policy.shouldRetry
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
maxAttempts: policy?.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,
|
|
35
|
+
initialIntervalMs: policy?.initialIntervalMs ?? DEFAULT_RETRY_POLICY.initialIntervalMs,
|
|
36
|
+
backoffCoefficient: policy?.backoffCoefficient ?? DEFAULT_RETRY_POLICY.backoffCoefficient,
|
|
37
|
+
maximumIntervalMs: policy?.maximumIntervalMs ?? DEFAULT_RETRY_POLICY.maximumIntervalMs
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function serializeRetryPolicy(policy) {
|
|
41
|
+
if (!policy) {
|
|
42
|
+
return {
|
|
43
|
+
hasDynamicPolicy: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (isDynamicRetryPolicy(policy)) {
|
|
47
|
+
return {
|
|
48
|
+
maxAttempts: policy.maxAttempts,
|
|
49
|
+
hasDynamicPolicy: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
maxAttempts: policy.maxAttempts,
|
|
54
|
+
initialIntervalMs: policy.initialIntervalMs,
|
|
55
|
+
backoffCoefficient: policy.backoffCoefficient,
|
|
56
|
+
maximumIntervalMs: policy.maximumIntervalMs,
|
|
57
|
+
hasDynamicPolicy: false
|
|
58
|
+
};
|
|
23
59
|
}
|
|
24
60
|
|
|
25
61
|
//# sourceMappingURL=retry.js.map
|
package/dist/core/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/retry.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/core/retry.ts"],"sourcesContent":["import type { SerializedError } from \"./error\";\n\nexport interface RetryDecision {\n shouldRetry: boolean;\n delayMs: number;\n}\n\nexport type RetryDecisionFn = (error: SerializedError, attempt: number) => RetryDecision;\n\nexport interface StaticRetryPolicy {\n maxAttempts?: number;\n initialIntervalMs?: number;\n backoffCoefficient?: number;\n maximumIntervalMs?: number;\n}\n\nexport interface DynamicRetryPolicy {\n maxAttempts?: number;\n shouldRetry: RetryDecisionFn;\n}\n\nexport type RetryPolicy = StaticRetryPolicy | DynamicRetryPolicy;\n\nexport interface SerializableRetryPolicy extends StaticRetryPolicy {\n hasDynamicPolicy?: boolean;\n}\n\nexport type MergedStaticRetryPolicy = Required<StaticRetryPolicy>;\n\nexport interface MergedDynamicRetryPolicy {\n maxAttempts: number;\n shouldRetry: RetryDecisionFn;\n}\n\nexport type MergedRetryPolicy = MergedStaticRetryPolicy | MergedDynamicRetryPolicy;\n\nexport const DEFAULT_RETRY_POLICY: Required<StaticRetryPolicy> = {\n maxAttempts: 5,\n initialIntervalMs: 1000,\n backoffCoefficient: 2,\n maximumIntervalMs: 60_000,\n};\n\nexport function isDynamicRetryPolicy(policy: RetryPolicy): policy is DynamicRetryPolicy {\n return \"shouldRetry\" in policy && typeof policy.shouldRetry === \"function\";\n}\n\nexport function isStaticRetryPolicy(policy: RetryPolicy): policy is StaticRetryPolicy {\n return !isDynamicRetryPolicy(policy);\n}\n\nexport function calculateRetryDelayMs(attemptNumber: number): number {\n const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;\n const backoffMs = initialIntervalMs * backoffCoefficient ** (attemptNumber - 1);\n return Math.min(backoffMs, maximumIntervalMs);\n}\n\nexport function shouldRetry(retryPolicy: StaticRetryPolicy, attemptNumber: number): boolean {\n const maxAttempts = retryPolicy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;\n return attemptNumber < maxAttempts;\n}\n\nexport function shouldRetryByPolicy(policy: StaticRetryPolicy, attemptNumber: number): boolean {\n const maxAttempts = policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;\n return attemptNumber < maxAttempts;\n}\n\nexport function mergeRetryPolicy(policy: StaticRetryPolicy | undefined): MergedStaticRetryPolicy;\nexport function mergeRetryPolicy(policy: DynamicRetryPolicy): MergedDynamicRetryPolicy;\nexport function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy;\nexport function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy {\n if (policy && isDynamicRetryPolicy(policy)) {\n return {\n maxAttempts: policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,\n shouldRetry: policy.shouldRetry,\n };\n }\n return {\n maxAttempts: policy?.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,\n initialIntervalMs: policy?.initialIntervalMs ?? DEFAULT_RETRY_POLICY.initialIntervalMs,\n backoffCoefficient: policy?.backoffCoefficient ?? DEFAULT_RETRY_POLICY.backoffCoefficient,\n maximumIntervalMs: policy?.maximumIntervalMs ?? DEFAULT_RETRY_POLICY.maximumIntervalMs,\n };\n}\n\nexport function serializeRetryPolicy(policy?: RetryPolicy): SerializableRetryPolicy {\n if (!policy) {\n return { hasDynamicPolicy: false };\n }\n\n if (isDynamicRetryPolicy(policy)) {\n return {\n maxAttempts: policy.maxAttempts,\n hasDynamicPolicy: true,\n };\n }\n\n return {\n maxAttempts: policy.maxAttempts,\n initialIntervalMs: policy.initialIntervalMs,\n backoffCoefficient: policy.backoffCoefficient,\n maximumIntervalMs: policy.maximumIntervalMs,\n hasDynamicPolicy: false,\n };\n}\n"],"names":["DEFAULT_RETRY_POLICY","maxAttempts","initialIntervalMs","backoffCoefficient","maximumIntervalMs","isDynamicRetryPolicy","policy","shouldRetry","isStaticRetryPolicy","calculateRetryDelayMs","attemptNumber","backoffMs","Math","min","retryPolicy","shouldRetryByPolicy","mergeRetryPolicy","serializeRetryPolicy","hasDynamicPolicy"],"mappings":"AAoCA,OAAO,MAAMA,uBAAoD;IAC/DC,aAA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AChC,OAAO;YACLL,aAAaK,OAAOL,WAAW;YAC/BiB,kBAAkB;QACpB;IACF;IAEA,OAAO;QACLjB,aAAaK,OAAOL,WAAW;QAC/BC,mBAAmBI,OAAOJ,iBAAiB;QAC3CC,oBAAoBG,OAAOH,kBAAkB;QAC7CC,mBAAmBE,OAAOF,iBAAiB;QAC3Cc,kBAAkB;IACpB;AACF"}
|
package/dist/core/retry.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { calculateRetryDelayMs, DEFAULT_RETRY_POLICY, shouldRetry } from "./retry.js";
|
|
2
|
+
import { calculateRetryDelayMs, DEFAULT_RETRY_POLICY, isDynamicRetryPolicy, isStaticRetryPolicy, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy } from "./retry.js";
|
|
3
3
|
describe("calculateRetryDelayMs", ()=>{
|
|
4
4
|
test("calculates exponential backoff correctly", ()=>{
|
|
5
5
|
expect(calculateRetryDelayMs(1)).toBe(1000);
|
|
@@ -8,12 +8,13 @@ describe("calculateRetryDelayMs", ()=>{
|
|
|
8
8
|
expect(calculateRetryDelayMs(4)).toBe(8000);
|
|
9
9
|
expect(calculateRetryDelayMs(5)).toBe(16_000);
|
|
10
10
|
expect(calculateRetryDelayMs(6)).toBe(32_000);
|
|
11
|
-
|
|
11
|
+
// attempt 7: 1s * 2^6 = 64s = 64000ms, capped at 60000ms (max)
|
|
12
|
+
expect(calculateRetryDelayMs(7)).toBe(60_000);
|
|
12
13
|
});
|
|
13
14
|
test("caps delay at maximum interval", ()=>{
|
|
14
15
|
const { maximumIntervalMs } = DEFAULT_RETRY_POLICY;
|
|
15
|
-
// attempt
|
|
16
|
-
expect(calculateRetryDelayMs(
|
|
16
|
+
// attempt 7: 1s * 2^6 = 64s = 64000ms, capped at 60000ms (max)
|
|
17
|
+
expect(calculateRetryDelayMs(7)).toBe(maximumIntervalMs);
|
|
17
18
|
// attempts 10 & 100: should still be capped
|
|
18
19
|
expect(calculateRetryDelayMs(10)).toBe(maximumIntervalMs);
|
|
19
20
|
expect(calculateRetryDelayMs(100)).toBe(maximumIntervalMs);
|
|
@@ -21,16 +22,176 @@ describe("calculateRetryDelayMs", ()=>{
|
|
|
21
22
|
test("handles edge cases", ()=>{
|
|
22
23
|
// attempt 0: 1s * 2^-1 = 0.5s = 500ms
|
|
23
24
|
expect(calculateRetryDelayMs(0)).toBe(500);
|
|
24
|
-
expect(calculateRetryDelayMs(Infinity)).toBe(
|
|
25
|
+
expect(calculateRetryDelayMs(Infinity)).toBe(60_000);
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
28
|
describe("shouldRetry", ()=>{
|
|
28
|
-
test("
|
|
29
|
-
|
|
30
|
-
expect(shouldRetry(
|
|
31
|
-
expect(shouldRetry(
|
|
32
|
-
expect(shouldRetry(
|
|
33
|
-
expect(shouldRetry(
|
|
29
|
+
test("returns false when attempt reaches maxAttempts", ()=>{
|
|
30
|
+
// 기본 정책: maxAttempts = 5
|
|
31
|
+
expect(shouldRetry(DEFAULT_RETRY_POLICY, 1)).toBe(true);
|
|
32
|
+
expect(shouldRetry(DEFAULT_RETRY_POLICY, 4)).toBe(true);
|
|
33
|
+
expect(shouldRetry(DEFAULT_RETRY_POLICY, 5)).toBe(false);
|
|
34
|
+
expect(shouldRetry(DEFAULT_RETRY_POLICY, 10)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("shouldRetryByPolicy", ()=>{
|
|
38
|
+
test("respects maxAttempts from policy", ()=>{
|
|
39
|
+
expect(shouldRetryByPolicy({
|
|
40
|
+
maxAttempts: 3
|
|
41
|
+
}, 1)).toBe(true);
|
|
42
|
+
expect(shouldRetryByPolicy({
|
|
43
|
+
maxAttempts: 3
|
|
44
|
+
}, 2)).toBe(true);
|
|
45
|
+
expect(shouldRetryByPolicy({
|
|
46
|
+
maxAttempts: 3
|
|
47
|
+
}, 3)).toBe(false);
|
|
48
|
+
expect(shouldRetryByPolicy({
|
|
49
|
+
maxAttempts: 3
|
|
50
|
+
}, 4)).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
test("uses default maxAttempts when not specified", ()=>{
|
|
53
|
+
expect(shouldRetryByPolicy({}, 1)).toBe(true);
|
|
54
|
+
expect(shouldRetryByPolicy({}, 4)).toBe(true);
|
|
55
|
+
expect(shouldRetryByPolicy({}, 5)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("isDynamicRetryPolicy", ()=>{
|
|
59
|
+
test("returns true for policy with shouldRetry function", ()=>{
|
|
60
|
+
const dynamicPolicy = {
|
|
61
|
+
maxAttempts: 3,
|
|
62
|
+
shouldRetry: ()=>({
|
|
63
|
+
shouldRetry: true,
|
|
64
|
+
delayMs: 1000
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
expect(isDynamicRetryPolicy(dynamicPolicy)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
test("returns false for static policy without shouldRetry", ()=>{
|
|
70
|
+
const staticPolicy = {
|
|
71
|
+
maxAttempts: 5,
|
|
72
|
+
initialIntervalMs: 1000
|
|
73
|
+
};
|
|
74
|
+
expect(isDynamicRetryPolicy(staticPolicy)).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
test("returns false for empty policy", ()=>{
|
|
77
|
+
expect(isDynamicRetryPolicy({})).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("isStaticRetryPolicy", ()=>{
|
|
81
|
+
test("returns true for static policy without shouldRetry", ()=>{
|
|
82
|
+
const staticPolicy = {
|
|
83
|
+
maxAttempts: 5,
|
|
84
|
+
initialIntervalMs: 1000
|
|
85
|
+
};
|
|
86
|
+
expect(isStaticRetryPolicy(staticPolicy)).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
test("returns true for empty policy", ()=>{
|
|
89
|
+
expect(isStaticRetryPolicy({})).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
test("returns false for dynamic policy", ()=>{
|
|
92
|
+
const dynamicPolicy = {
|
|
93
|
+
maxAttempts: 3,
|
|
94
|
+
shouldRetry: ()=>({
|
|
95
|
+
shouldRetry: true,
|
|
96
|
+
delayMs: 1000
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
expect(isStaticRetryPolicy(dynamicPolicy)).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("mergeRetryPolicy", ()=>{
|
|
103
|
+
test("returns default values when policy is undefined", ()=>{
|
|
104
|
+
const merged = mergeRetryPolicy(undefined);
|
|
105
|
+
expect(merged.maxAttempts).toBe(5);
|
|
106
|
+
expect(merged.initialIntervalMs).toBe(1000);
|
|
107
|
+
expect(merged.backoffCoefficient).toBe(2);
|
|
108
|
+
expect(merged.maximumIntervalMs).toBe(60_000);
|
|
109
|
+
});
|
|
110
|
+
test("uses provided values and fills missing with defaults for static policy", ()=>{
|
|
111
|
+
const merged = mergeRetryPolicy({
|
|
112
|
+
maxAttempts: 10,
|
|
113
|
+
initialIntervalMs: 500
|
|
114
|
+
});
|
|
115
|
+
expect(merged.maxAttempts).toBe(10);
|
|
116
|
+
expect(merged.initialIntervalMs).toBe(500);
|
|
117
|
+
expect(merged.backoffCoefficient).toBe(2);
|
|
118
|
+
expect(merged.maximumIntervalMs).toBe(60_000);
|
|
119
|
+
});
|
|
120
|
+
test("returns only maxAttempts and shouldRetry for dynamic policy", ()=>{
|
|
121
|
+
const customFn = (_error, _attempt)=>({
|
|
122
|
+
shouldRetry: false,
|
|
123
|
+
delayMs: 5000
|
|
124
|
+
});
|
|
125
|
+
const dynamicPolicy = {
|
|
126
|
+
maxAttempts: 3,
|
|
127
|
+
shouldRetry: customFn
|
|
128
|
+
};
|
|
129
|
+
const merged = mergeRetryPolicy(dynamicPolicy);
|
|
130
|
+
expect(merged.maxAttempts).toBe(3);
|
|
131
|
+
expect(merged.shouldRetry).toBe(customFn);
|
|
132
|
+
// 동적 정책에서는 backoff 필드들이 없어야 합니다.
|
|
133
|
+
expect("initialIntervalMs" in merged).toBe(false);
|
|
134
|
+
expect("backoffCoefficient" in merged).toBe(false);
|
|
135
|
+
expect("maximumIntervalMs" in merged).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
test("uses default maxAttempts for dynamic policy when not specified", ()=>{
|
|
138
|
+
const customFn = ()=>({
|
|
139
|
+
shouldRetry: true,
|
|
140
|
+
delayMs: 1000
|
|
141
|
+
});
|
|
142
|
+
const dynamicPolicy = {
|
|
143
|
+
shouldRetry: customFn
|
|
144
|
+
};
|
|
145
|
+
const merged = mergeRetryPolicy(dynamicPolicy);
|
|
146
|
+
expect(merged.maxAttempts).toBe(5); // 기본값
|
|
147
|
+
expect(merged.shouldRetry).toBe(customFn);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("serializeRetryPolicy", ()=>{
|
|
151
|
+
test("returns empty object with hasDynamicPolicy=false for undefined", ()=>{
|
|
152
|
+
const serialized = serializeRetryPolicy(undefined);
|
|
153
|
+
expect(serialized.hasDynamicPolicy).toBe(false);
|
|
154
|
+
expect(serialized.maxAttempts).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
test("serializes static fields for static policy", ()=>{
|
|
157
|
+
const serialized = serializeRetryPolicy({
|
|
158
|
+
maxAttempts: 10,
|
|
159
|
+
initialIntervalMs: 2000
|
|
160
|
+
});
|
|
161
|
+
expect(serialized.maxAttempts).toBe(10);
|
|
162
|
+
expect(serialized.initialIntervalMs).toBe(2000);
|
|
163
|
+
expect(serialized.hasDynamicPolicy).toBe(false);
|
|
164
|
+
expect("shouldRetry" in serialized).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
test("excludes backoff fields for dynamic policy", ()=>{
|
|
167
|
+
const dynamicPolicy = {
|
|
168
|
+
maxAttempts: 3,
|
|
169
|
+
shouldRetry: ()=>({
|
|
170
|
+
shouldRetry: true,
|
|
171
|
+
delayMs: 1000
|
|
172
|
+
})
|
|
173
|
+
};
|
|
174
|
+
const serialized = serializeRetryPolicy(dynamicPolicy);
|
|
175
|
+
expect(serialized.maxAttempts).toBe(3);
|
|
176
|
+
expect(serialized.hasDynamicPolicy).toBe(true);
|
|
177
|
+
// 동적 정책에서는 backoff 필드들이 없어야 합니다.
|
|
178
|
+
expect(serialized.initialIntervalMs).toBeUndefined();
|
|
179
|
+
expect(serialized.backoffCoefficient).toBeUndefined();
|
|
180
|
+
expect(serialized.maximumIntervalMs).toBeUndefined();
|
|
181
|
+
});
|
|
182
|
+
test("includes backoff fields for static policy", ()=>{
|
|
183
|
+
const staticPolicy = {
|
|
184
|
+
maxAttempts: 5,
|
|
185
|
+
initialIntervalMs: 2000,
|
|
186
|
+
backoffCoefficient: 3,
|
|
187
|
+
maximumIntervalMs: 30000
|
|
188
|
+
};
|
|
189
|
+
const serialized = serializeRetryPolicy(staticPolicy);
|
|
190
|
+
expect(serialized.maxAttempts).toBe(5);
|
|
191
|
+
expect(serialized.initialIntervalMs).toBe(2000);
|
|
192
|
+
expect(serialized.backoffCoefficient).toBe(3);
|
|
193
|
+
expect(serialized.maximumIntervalMs).toBe(30000);
|
|
194
|
+
expect(serialized.hasDynamicPolicy).toBe(false);
|
|
34
195
|
});
|
|
35
196
|
});
|
|
36
197
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/retry.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport { calculateRetryDelayMs, DEFAULT_RETRY_POLICY, shouldRetry } from \"./retry\";\n\ndescribe(\"calculateRetryDelayMs\", () => {\n test(\"calculates exponential backoff correctly\", () => {\n expect(calculateRetryDelayMs(1)).toBe(1000);\n expect(calculateRetryDelayMs(2)).toBe(2000);\n expect(calculateRetryDelayMs(3)).toBe(4000);\n expect(calculateRetryDelayMs(4)).toBe(8000);\n expect(calculateRetryDelayMs(5)).toBe(16_000);\n expect(calculateRetryDelayMs(6)).toBe(32_000);\n expect(calculateRetryDelayMs(7)).toBe(64_000);\n });\n\n test(\"caps delay at maximum interval\", () => {\n const { maximumIntervalMs } = DEFAULT_RETRY_POLICY;\n\n // attempt 8: 1s * 2^7 = 128s = 128000ms, but capped at 100000ms (max)\n expect(calculateRetryDelayMs(8)).toBe(maximumIntervalMs);\n\n // attempts 10 & 100: should still be capped\n expect(calculateRetryDelayMs(10)).toBe(maximumIntervalMs);\n expect(calculateRetryDelayMs(100)).toBe(maximumIntervalMs);\n });\n\n test(\"handles edge cases\", () => {\n // attempt 0: 1s * 2^-1 = 0.5s = 500ms\n expect(calculateRetryDelayMs(0)).toBe(500);\n expect(calculateRetryDelayMs(Infinity)).toBe(100_000);\n });\n});\n\ndescribe(\"shouldRetry\", () => {\n test(\"always returns true with default policy (infinite retries)\", () => {\n const retryPolicy = DEFAULT_RETRY_POLICY;\n expect(shouldRetry(retryPolicy, 1)).toBe(true);\n expect(shouldRetry(retryPolicy, 10)).toBe(true);\n expect(shouldRetry(retryPolicy, 100)).toBe(true);\n expect(shouldRetry(retryPolicy, 1000)).toBe(true);\n });\n});\n"],"names":["describe","expect","test","calculateRetryDelayMs","DEFAULT_RETRY_POLICY","shouldRetry","toBe","maximumIntervalMs","Infinity","retryPolicy"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAChD,SAASC,qBAAqB,EAAEC,oBAAoB,EAAEC,WAAW,QAAQ,aAAU;AAEnFL,SAAS,yBAAyB;IAChCE,KAAK,4CAA4C;QAC/CD,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;IACxC;IAEAJ,KAAK,kCAAkC;QACrC,MAAM,EAAEK,iBAAiB,EAAE,GAAGH;QAE9B,sEAAsE;QACtEH,OAAOE,sBAAsB,IAAIG,IAAI,CAACC;QAEtC,4CAA4C;QAC5CN,OAAOE,sBAAsB,KAAKG,IAAI,CAACC;QACvCN,OAAOE,sBAAsB,MAAMG,IAAI,CAACC;IAC1C;IAEAL,KAAK,sBAAsB;QACzB,sCAAsC;QACtCD,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsBK,WAAWF,IAAI,CAAC;IAC/C;AACF;AAEAN,SAAS,eAAe;IACtBE,KAAK,8DAA8D;QACjE,MAAMO,cAAcL;QACpBH,OAAOI,YAAYI,aAAa,IAAIH,IAAI,CAAC;QACzCL,OAAOI,YAAYI,aAAa,KAAKH,IAAI,CAAC;QAC1CL,OAAOI,YAAYI,aAAa,MAAMH,IAAI,CAAC;QAC3CL,OAAOI,YAAYI,aAAa,OAAOH,IAAI,CAAC;IAC9C;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/core/retry.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport type { SerializedError } from \"./error\";\nimport type { DynamicRetryPolicy, StaticRetryPolicy } from \"./retry\";\nimport {\n calculateRetryDelayMs,\n DEFAULT_RETRY_POLICY,\n isDynamicRetryPolicy,\n isStaticRetryPolicy,\n mergeRetryPolicy,\n serializeRetryPolicy,\n shouldRetry,\n shouldRetryByPolicy,\n} from \"./retry\";\n\ndescribe(\"calculateRetryDelayMs\", () => {\n test(\"calculates exponential backoff correctly\", () => {\n expect(calculateRetryDelayMs(1)).toBe(1000);\n expect(calculateRetryDelayMs(2)).toBe(2000);\n expect(calculateRetryDelayMs(3)).toBe(4000);\n expect(calculateRetryDelayMs(4)).toBe(8000);\n expect(calculateRetryDelayMs(5)).toBe(16_000);\n expect(calculateRetryDelayMs(6)).toBe(32_000);\n // attempt 7: 1s * 2^6 = 64s = 64000ms, capped at 60000ms (max)\n expect(calculateRetryDelayMs(7)).toBe(60_000);\n });\n\n test(\"caps delay at maximum interval\", () => {\n const { maximumIntervalMs } = DEFAULT_RETRY_POLICY;\n\n // attempt 7: 1s * 2^6 = 64s = 64000ms, capped at 60000ms (max)\n expect(calculateRetryDelayMs(7)).toBe(maximumIntervalMs);\n\n // attempts 10 & 100: should still be capped\n expect(calculateRetryDelayMs(10)).toBe(maximumIntervalMs);\n expect(calculateRetryDelayMs(100)).toBe(maximumIntervalMs);\n });\n\n test(\"handles edge cases\", () => {\n // attempt 0: 1s * 2^-1 = 0.5s = 500ms\n expect(calculateRetryDelayMs(0)).toBe(500);\n expect(calculateRetryDelayMs(Infinity)).toBe(60_000);\n });\n});\n\ndescribe(\"shouldRetry\", () => {\n test(\"returns false when attempt reaches maxAttempts\", () => {\n // 기본 정책: maxAttempts = 5\n expect(shouldRetry(DEFAULT_RETRY_POLICY, 1)).toBe(true);\n expect(shouldRetry(DEFAULT_RETRY_POLICY, 4)).toBe(true);\n expect(shouldRetry(DEFAULT_RETRY_POLICY, 5)).toBe(false);\n expect(shouldRetry(DEFAULT_RETRY_POLICY, 10)).toBe(false);\n });\n});\n\ndescribe(\"shouldRetryByPolicy\", () => {\n test(\"respects maxAttempts from policy\", () => {\n expect(shouldRetryByPolicy({ maxAttempts: 3 }, 1)).toBe(true);\n expect(shouldRetryByPolicy({ maxAttempts: 3 }, 2)).toBe(true);\n expect(shouldRetryByPolicy({ maxAttempts: 3 }, 3)).toBe(false);\n expect(shouldRetryByPolicy({ maxAttempts: 3 }, 4)).toBe(false);\n });\n\n test(\"uses default maxAttempts when not specified\", () => {\n expect(shouldRetryByPolicy({}, 1)).toBe(true);\n expect(shouldRetryByPolicy({}, 4)).toBe(true);\n expect(shouldRetryByPolicy({}, 5)).toBe(false);\n });\n});\n\ndescribe(\"isDynamicRetryPolicy\", () => {\n test(\"returns true for policy with shouldRetry function\", () => {\n const dynamicPolicy: DynamicRetryPolicy = {\n maxAttempts: 3,\n shouldRetry: () => ({ shouldRetry: true, delayMs: 1000 }),\n };\n expect(isDynamicRetryPolicy(dynamicPolicy)).toBe(true);\n });\n\n test(\"returns false for static policy without shouldRetry\", () => {\n const staticPolicy: StaticRetryPolicy = {\n maxAttempts: 5,\n initialIntervalMs: 1000,\n };\n expect(isDynamicRetryPolicy(staticPolicy)).toBe(false);\n });\n\n test(\"returns false for empty policy\", () => {\n expect(isDynamicRetryPolicy({})).toBe(false);\n });\n});\n\ndescribe(\"isStaticRetryPolicy\", () => {\n test(\"returns true for static policy without shouldRetry\", () => {\n const staticPolicy: StaticRetryPolicy = {\n maxAttempts: 5,\n initialIntervalMs: 1000,\n };\n expect(isStaticRetryPolicy(staticPolicy)).toBe(true);\n });\n\n test(\"returns true for empty policy\", () => {\n expect(isStaticRetryPolicy({})).toBe(true);\n });\n\n test(\"returns false for dynamic policy\", () => {\n const dynamicPolicy: DynamicRetryPolicy = {\n maxAttempts: 3,\n shouldRetry: () => ({ shouldRetry: true, delayMs: 1000 }),\n };\n expect(isStaticRetryPolicy(dynamicPolicy)).toBe(false);\n });\n});\n\ndescribe(\"mergeRetryPolicy\", () => {\n test(\"returns default values when policy is undefined\", () => {\n const merged = mergeRetryPolicy(undefined);\n expect(merged.maxAttempts).toBe(5);\n expect(merged.initialIntervalMs).toBe(1000);\n expect(merged.backoffCoefficient).toBe(2);\n expect(merged.maximumIntervalMs).toBe(60_000);\n });\n\n test(\"uses provided values and fills missing with defaults for static policy\", () => {\n const merged = mergeRetryPolicy({ maxAttempts: 10, initialIntervalMs: 500 });\n expect(merged.maxAttempts).toBe(10);\n expect(merged.initialIntervalMs).toBe(500);\n expect(merged.backoffCoefficient).toBe(2);\n expect(merged.maximumIntervalMs).toBe(60_000);\n });\n\n test(\"returns only maxAttempts and shouldRetry for dynamic policy\", () => {\n const customFn = (_error: SerializedError, _attempt: number) => ({\n shouldRetry: false,\n delayMs: 5000,\n });\n const dynamicPolicy: DynamicRetryPolicy = {\n maxAttempts: 3,\n shouldRetry: customFn,\n };\n const merged = mergeRetryPolicy(dynamicPolicy);\n\n expect(merged.maxAttempts).toBe(3);\n expect(merged.shouldRetry).toBe(customFn);\n // 동적 정책에서는 backoff 필드들이 없어야 합니다.\n expect(\"initialIntervalMs\" in merged).toBe(false);\n expect(\"backoffCoefficient\" in merged).toBe(false);\n expect(\"maximumIntervalMs\" in merged).toBe(false);\n });\n\n test(\"uses default maxAttempts for dynamic policy when not specified\", () => {\n const customFn = () => ({ shouldRetry: true, delayMs: 1000 });\n const dynamicPolicy: DynamicRetryPolicy = {\n shouldRetry: customFn,\n };\n const merged = mergeRetryPolicy(dynamicPolicy);\n\n expect(merged.maxAttempts).toBe(5); // 기본값\n expect(merged.shouldRetry).toBe(customFn);\n });\n});\n\ndescribe(\"serializeRetryPolicy\", () => {\n test(\"returns empty object with hasDynamicPolicy=false for undefined\", () => {\n const serialized = serializeRetryPolicy(undefined);\n expect(serialized.hasDynamicPolicy).toBe(false);\n expect(serialized.maxAttempts).toBeUndefined();\n });\n\n test(\"serializes static fields for static policy\", () => {\n const serialized = serializeRetryPolicy({\n maxAttempts: 10,\n initialIntervalMs: 2000,\n });\n expect(serialized.maxAttempts).toBe(10);\n expect(serialized.initialIntervalMs).toBe(2000);\n expect(serialized.hasDynamicPolicy).toBe(false);\n expect(\"shouldRetry\" in serialized).toBe(false);\n });\n\n test(\"excludes backoff fields for dynamic policy\", () => {\n const dynamicPolicy: DynamicRetryPolicy = {\n maxAttempts: 3,\n shouldRetry: () => ({ shouldRetry: true, delayMs: 1000 }),\n };\n const serialized = serializeRetryPolicy(dynamicPolicy);\n\n expect(serialized.maxAttempts).toBe(3);\n expect(serialized.hasDynamicPolicy).toBe(true);\n // 동적 정책에서는 backoff 필드들이 없어야 합니다.\n expect(serialized.initialIntervalMs).toBeUndefined();\n expect(serialized.backoffCoefficient).toBeUndefined();\n expect(serialized.maximumIntervalMs).toBeUndefined();\n });\n\n test(\"includes backoff fields for static policy\", () => {\n const staticPolicy: StaticRetryPolicy = {\n maxAttempts: 5,\n initialIntervalMs: 2000,\n backoffCoefficient: 3,\n maximumIntervalMs: 30000,\n };\n const serialized = serializeRetryPolicy(staticPolicy);\n\n expect(serialized.maxAttempts).toBe(5);\n expect(serialized.initialIntervalMs).toBe(2000);\n expect(serialized.backoffCoefficient).toBe(3);\n expect(serialized.maximumIntervalMs).toBe(30000);\n expect(serialized.hasDynamicPolicy).toBe(false);\n });\n});\n"],"names":["describe","expect","test","calculateRetryDelayMs","DEFAULT_RETRY_POLICY","isDynamicRetryPolicy","isStaticRetryPolicy","mergeRetryPolicy","serializeRetryPolicy","shouldRetry","shouldRetryByPolicy","toBe","maximumIntervalMs","Infinity","maxAttempts","dynamicPolicy","delayMs","staticPolicy","initialIntervalMs","merged","undefined","backoffCoefficient","customFn","_error","_attempt","serialized","hasDynamicPolicy","toBeUndefined"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAGhD,SACEC,qBAAqB,EACrBC,oBAAoB,EACpBC,oBAAoB,EACpBC,mBAAmB,EACnBC,gBAAgB,EAChBC,oBAAoB,EACpBC,WAAW,EACXC,mBAAmB,QACd,aAAU;AAEjBV,SAAS,yBAAyB;IAChCE,KAAK,4CAA4C;QAC/CD,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtCV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtCV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtCV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtCV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtCV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;QACtC,+DAA+D;QAC/DV,OAAOE,sBAAsB,IAAIQ,IAAI,CAAC;IACxC;IAEAT,KAAK,kCAAkC;QACrC,MAAM,EAAEU,iBAAiB,EAAE,GAAGR;QAE9B,+DAA+D;QAC/DH,OAAOE,sBAAsB,IAAIQ,IAAI,CAACC;QAEtC,4CAA4C;QAC5CX,OAAOE,sBAAsB,KAAKQ,I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