@sonamu-kit/tasks 0.1.3 → 0.3.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.
Files changed (215) hide show
  1. package/.oxlintrc.json +3 -0
  2. package/AGENTS.md +21 -0
  3. package/dist/backend.d.ts +126 -103
  4. package/dist/backend.d.ts.map +1 -1
  5. package/dist/backend.js +4 -1
  6. package/dist/backend.js.map +1 -1
  7. package/dist/client.d.ts +145 -132
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +220 -212
  10. package/dist/client.js.map +1 -1
  11. package/dist/config.d.ts +15 -8
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +22 -17
  14. package/dist/config.js.map +1 -1
  15. package/dist/core/duration.d.ts +5 -4
  16. package/dist/core/duration.d.ts.map +1 -1
  17. package/dist/core/duration.js +54 -59
  18. package/dist/core/duration.js.map +1 -1
  19. package/dist/core/error.d.ts +10 -7
  20. package/dist/core/error.d.ts.map +1 -1
  21. package/dist/core/error.js +21 -21
  22. package/dist/core/error.js.map +1 -1
  23. package/dist/core/json.d.ts +8 -3
  24. package/dist/core/json.d.ts.map +1 -1
  25. package/dist/core/result.d.ts +10 -14
  26. package/dist/core/result.d.ts.map +1 -1
  27. package/dist/core/result.js +21 -16
  28. package/dist/core/result.js.map +1 -1
  29. package/dist/core/retry.d.ts +42 -20
  30. package/dist/core/retry.d.ts.map +1 -1
  31. package/dist/core/retry.js +49 -20
  32. package/dist/core/retry.js.map +1 -1
  33. package/dist/core/schema.d.ts +57 -53
  34. package/dist/core/schema.d.ts.map +1 -1
  35. package/dist/core/step.d.ts +28 -78
  36. package/dist/core/step.d.ts.map +1 -1
  37. package/dist/core/step.js +53 -63
  38. package/dist/core/step.js.map +1 -1
  39. package/dist/core/workflow.d.ts +33 -61
  40. package/dist/core/workflow.d.ts.map +1 -1
  41. package/dist/core/workflow.js +31 -41
  42. package/dist/core/workflow.js.map +1 -1
  43. package/dist/database/backend.d.ts +53 -46
  44. package/dist/database/backend.d.ts.map +1 -1
  45. package/dist/database/backend.js +544 -545
  46. package/dist/database/backend.js.map +1 -1
  47. package/dist/database/base.js +48 -25
  48. package/dist/database/base.js.map +1 -1
  49. package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
  50. package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
  51. package/dist/database/migrations/20251212000000_0_init.js +8 -4
  52. package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
  53. package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
  54. package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
  55. package/dist/database/migrations/20251212000000_1_tables.js +81 -83
  56. package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
  57. package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
  58. package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
  59. package/dist/database/migrations/20251212000000_2_fk.js +20 -43
  60. package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
  61. package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
  62. package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
  63. package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
  64. package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
  65. package/dist/database/pubsub.d.ts +7 -16
  66. package/dist/database/pubsub.d.ts.map +1 -1
  67. package/dist/database/pubsub.js +75 -73
  68. package/dist/database/pubsub.js.map +1 -1
  69. package/dist/execution.d.ts +20 -57
  70. package/dist/execution.d.ts.map +1 -1
  71. package/dist/execution.js +175 -174
  72. package/dist/execution.js.map +1 -1
  73. package/dist/index.d.ts +5 -8
  74. package/dist/index.js +5 -5
  75. package/dist/internal.d.ts +12 -12
  76. package/dist/internal.js +4 -4
  77. package/dist/registry.d.ts +33 -27
  78. package/dist/registry.d.ts.map +1 -1
  79. package/dist/registry.js +58 -49
  80. package/dist/registry.js.map +1 -1
  81. package/dist/worker.d.ts +57 -50
  82. package/dist/worker.d.ts.map +1 -1
  83. package/dist/worker.js +194 -198
  84. package/dist/worker.js.map +1 -1
  85. package/dist/workflow.d.ts +26 -27
  86. package/dist/workflow.d.ts.map +1 -1
  87. package/dist/workflow.js +20 -15
  88. package/dist/workflow.js.map +1 -1
  89. package/nodemon.json +1 -1
  90. package/package.json +18 -20
  91. package/src/backend.ts +28 -8
  92. package/src/chaos.test.ts +3 -1
  93. package/src/client.test.ts +2 -0
  94. package/src/client.ts +32 -8
  95. package/src/config.test.ts +1 -0
  96. package/src/config.ts +3 -2
  97. package/src/core/duration.test.ts +2 -1
  98. package/src/core/duration.ts +1 -1
  99. package/src/core/error.test.ts +1 -0
  100. package/src/core/error.ts +1 -1
  101. package/src/core/result.test.ts +1 -0
  102. package/src/core/retry.test.ts +181 -11
  103. package/src/core/retry.ts +95 -19
  104. package/src/core/schema.ts +2 -2
  105. package/src/core/step.test.ts +2 -1
  106. package/src/core/step.ts +4 -3
  107. package/src/core/workflow.test.ts +2 -1
  108. package/src/core/workflow.ts +4 -3
  109. package/src/database/backend.test.ts +1 -0
  110. package/src/database/backend.testsuite.ts +162 -39
  111. package/src/database/backend.ts +271 -35
  112. package/src/database/base.test.ts +41 -0
  113. package/src/database/base.ts +51 -2
  114. package/src/database/migrations/20251212000000_0_init.ts +2 -1
  115. package/src/database/migrations/20251212000000_1_tables.ts +2 -1
  116. package/src/database/migrations/20251212000000_2_fk.ts +2 -1
  117. package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
  118. package/src/database/pubsub.test.ts +6 -3
  119. package/src/database/pubsub.ts +55 -33
  120. package/src/execution.test.ts +117 -0
  121. package/src/execution.ts +65 -10
  122. package/src/internal.ts +21 -1
  123. package/src/practices/01-remote-workflow.ts +1 -0
  124. package/src/registry.test.ts +1 -0
  125. package/src/registry.ts +1 -1
  126. package/src/testing/connection.ts +3 -1
  127. package/src/worker.test.ts +2 -0
  128. package/src/worker.ts +31 -9
  129. package/src/workflow.test.ts +1 -0
  130. package/src/workflow.ts +5 -2
  131. package/templates/openworkflow.config.ts +2 -1
  132. package/tsdown.config.ts +31 -0
  133. package/.swcrc +0 -17
  134. package/dist/chaos.test.d.ts +0 -2
  135. package/dist/chaos.test.d.ts.map +0 -1
  136. package/dist/chaos.test.js +0 -92
  137. package/dist/chaos.test.js.map +0 -1
  138. package/dist/client.test.d.ts +0 -2
  139. package/dist/client.test.d.ts.map +0 -1
  140. package/dist/client.test.js +0 -340
  141. package/dist/client.test.js.map +0 -1
  142. package/dist/config.test.d.ts +0 -2
  143. package/dist/config.test.d.ts.map +0 -1
  144. package/dist/config.test.js +0 -24
  145. package/dist/config.test.js.map +0 -1
  146. package/dist/core/duration.test.d.ts +0 -2
  147. package/dist/core/duration.test.d.ts.map +0 -1
  148. package/dist/core/duration.test.js +0 -265
  149. package/dist/core/duration.test.js.map +0 -1
  150. package/dist/core/error.test.d.ts +0 -2
  151. package/dist/core/error.test.d.ts.map +0 -1
  152. package/dist/core/error.test.js +0 -63
  153. package/dist/core/error.test.js.map +0 -1
  154. package/dist/core/json.js +0 -3
  155. package/dist/core/json.js.map +0 -1
  156. package/dist/core/result.test.d.ts +0 -2
  157. package/dist/core/result.test.d.ts.map +0 -1
  158. package/dist/core/result.test.js +0 -19
  159. package/dist/core/result.test.js.map +0 -1
  160. package/dist/core/retry.test.d.ts +0 -2
  161. package/dist/core/retry.test.d.ts.map +0 -1
  162. package/dist/core/retry.test.js +0 -37
  163. package/dist/core/retry.test.js.map +0 -1
  164. package/dist/core/schema.js +0 -4
  165. package/dist/core/schema.js.map +0 -1
  166. package/dist/core/step.test.d.ts +0 -2
  167. package/dist/core/step.test.d.ts.map +0 -1
  168. package/dist/core/step.test.js +0 -356
  169. package/dist/core/step.test.js.map +0 -1
  170. package/dist/core/workflow.test.d.ts +0 -2
  171. package/dist/core/workflow.test.d.ts.map +0 -1
  172. package/dist/core/workflow.test.js +0 -172
  173. package/dist/core/workflow.test.js.map +0 -1
  174. package/dist/database/backend.test.d.ts +0 -2
  175. package/dist/database/backend.test.d.ts.map +0 -1
  176. package/dist/database/backend.test.js +0 -19
  177. package/dist/database/backend.test.js.map +0 -1
  178. package/dist/database/backend.testsuite.d.ts +0 -20
  179. package/dist/database/backend.testsuite.d.ts.map +0 -1
  180. package/dist/database/backend.testsuite.js +0 -1174
  181. package/dist/database/backend.testsuite.js.map +0 -1
  182. package/dist/database/base.d.ts +0 -12
  183. package/dist/database/base.d.ts.map +0 -1
  184. package/dist/database/pubsub.test.d.ts +0 -2
  185. package/dist/database/pubsub.test.d.ts.map +0 -1
  186. package/dist/database/pubsub.test.js +0 -86
  187. package/dist/database/pubsub.test.js.map +0 -1
  188. package/dist/execution.test.d.ts +0 -2
  189. package/dist/execution.test.d.ts.map +0 -1
  190. package/dist/execution.test.js +0 -558
  191. package/dist/execution.test.js.map +0 -1
  192. package/dist/index.d.ts.map +0 -1
  193. package/dist/index.js.map +0 -1
  194. package/dist/internal.d.ts.map +0 -1
  195. package/dist/internal.js.map +0 -1
  196. package/dist/practices/01-remote-workflow.d.ts +0 -2
  197. package/dist/practices/01-remote-workflow.d.ts.map +0 -1
  198. package/dist/practices/01-remote-workflow.js +0 -70
  199. package/dist/practices/01-remote-workflow.js.map +0 -1
  200. package/dist/registry.test.d.ts +0 -2
  201. package/dist/registry.test.d.ts.map +0 -1
  202. package/dist/registry.test.js +0 -95
  203. package/dist/registry.test.js.map +0 -1
  204. package/dist/testing/connection.d.ts +0 -7
  205. package/dist/testing/connection.d.ts.map +0 -1
  206. package/dist/testing/connection.js +0 -39
  207. package/dist/testing/connection.js.map +0 -1
  208. package/dist/worker.test.d.ts +0 -2
  209. package/dist/worker.test.d.ts.map +0 -1
  210. package/dist/worker.test.js +0 -1164
  211. package/dist/worker.test.js.map +0 -1
  212. package/dist/workflow.test.d.ts +0 -2
  213. package/dist/workflow.test.d.ts.map +0 -1
  214. package/dist/workflow.test.js +0 -73
  215. package/dist/workflow.test.js.map +0 -1
@@ -1,82 +1,45 @@
1
- import type { Backend } from "./backend";
2
- import type { DurationString } from "./core/duration";
3
- import type { StepAttempt } from "./core/step";
4
- import type { WorkflowRun } from "./core/workflow";
1
+ import { DurationString } from "./core/duration.js";
2
+
3
+ //#region src/execution.d.ts
4
+
5
5
  /**
6
6
  * Config for an individual step defined with `step.run()`.
7
7
  */
8
- export interface StepFunctionConfig {
9
- /**
10
- * The name of the step.
11
- */
12
- name: string;
8
+ interface StepFunctionConfig {
9
+ /**
10
+ * The name of the step.
11
+ */
12
+ name: string;
13
13
  }
14
14
  /**
15
15
  * Represents the API for defining steps within a workflow. Used within a
16
16
  * workflow handler to define steps by calling `step.run()`.
17
17
  */
18
- export interface StepApi {
19
- run<Output>(config: Readonly<StepFunctionConfig>, fn: StepFunction<Output>): Promise<Output>;
20
- sleep(name: string, duration: DurationString): Promise<void>;
18
+ interface StepApi {
19
+ run<Output>(config: Readonly<StepFunctionConfig>, fn: StepFunction<Output>): Promise<Output>;
20
+ sleep(name: string, duration: DurationString): Promise<void>;
21
21
  }
22
22
  /**
23
23
  * The step definition (defined by the user) that executes user code. Can return
24
24
  * undefined (e.g., when using `return;`) which will be converted to null.
25
25
  */
26
- export type StepFunction<Output> = () => Promise<Output | undefined> | Output | undefined;
26
+ type StepFunction<Output> = () => Promise<Output | undefined> | Output | undefined;
27
27
  /**
28
28
  * Params passed to a workflow function for the user to use when defining steps.
29
29
  */
30
- export interface WorkflowFunctionParams<Input> {
31
- input: Input;
32
- step: StepApi;
33
- version: string | null;
30
+ interface WorkflowFunctionParams<Input> {
31
+ input: Input;
32
+ step: StepApi;
33
+ version: string | null;
34
34
  }
35
35
  /**
36
36
  * The workflow definition's function (defined by the user) that the user uses
37
37
  * to define the workflow's steps.
38
38
  */
39
- export type WorkflowFunction<Input, Output> = (params: Readonly<WorkflowFunctionParams<Input>>) => Promise<Output> | Output;
39
+ type WorkflowFunction<Input, Output> = (params: Readonly<WorkflowFunctionParams<Input>>) => Promise<Output> | Output;
40
40
  /**
41
41
  * Configures the options for a StepExecutor.
42
42
  */
43
- export interface StepExecutorOptions {
44
- backend: Backend;
45
- workflowRunId: string;
46
- workerId: string;
47
- attempts: StepAttempt[];
48
- }
49
- /**
50
- * Replays prior step attempts and persists new ones while memoizing
51
- * deterministic step outputs.
52
- */
53
- export declare class StepExecutor implements StepApi {
54
- private readonly backend;
55
- private readonly workflowRunId;
56
- private readonly workerId;
57
- private cache;
58
- constructor(options: Readonly<StepExecutorOptions>);
59
- run<Output>(config: Readonly<StepFunctionConfig>, fn: StepFunction<Output>): Promise<Output>;
60
- sleep(name: string, duration: DurationString): Promise<void>;
61
- }
62
- /**
63
- * Parameters for the workflow execution use case.
64
- */
65
- export interface ExecuteWorkflowParams {
66
- backend: Backend;
67
- workflowRun: WorkflowRun;
68
- workflowFn: WorkflowFunction<unknown, unknown>;
69
- workflowVersion: string | null;
70
- workerId: string;
71
- }
72
- /**
73
- * Execute a workflow run. This is the core application use case that handles:
74
- * - Loading step history
75
- * - Handling sleeping steps
76
- * - Creating the step executor
77
- * - Executing the workflow function
78
- * - Completing, failing, or sleeping the workflow run based on the outcome
79
- * @param params - The execution parameters
80
- */
81
- export declare function executeWorkflow(params: Readonly<ExecuteWorkflowParams>): Promise<void>;
43
+ //#endregion
44
+ export { StepApi, WorkflowFunction };
82
45
  //# sourceMappingURL=execution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,aAAa,CAAC;AASjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MA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BAAuB,YACrC,QAAQ,UAAU"}
package/dist/execution.js CHANGED
@@ -1,182 +1,183 @@
1
+ import { isDynamicRetryPolicy } from "./core/retry.js";
1
2
  import { serializeError } from "./core/error.js";
2
3
  import { addToStepAttemptCache, calculateSleepResumeAt, createSleepContext, createStepAttemptCacheFromAttempts, getCachedStepAttempt, normalizeStepOutput } from "./core/step.js";
4
+
5
+ //#region src/execution.ts
3
6
  /**
4
- * Signal thrown when a workflow needs to sleep. Contains the time when the
5
- * workflow should resume.
6
- */ class SleepSignal extends Error {
7
- resumeAt;
8
- constructor(resumeAt){
9
- super("SleepSignal");
10
- this.name = "SleepSignal";
11
- this.resumeAt = resumeAt;
12
- }
13
- }
7
+ * Signal thrown when a workflow needs to sleep. Contains the time when the
8
+ * workflow should resume.
9
+ */
10
+ var SleepSignal = class extends Error {
11
+ resumeAt;
12
+ constructor(resumeAt) {
13
+ super("SleepSignal");
14
+ this.name = "SleepSignal";
15
+ this.resumeAt = resumeAt;
16
+ }
17
+ };
14
18
  /**
15
- * Replays prior step attempts and persists new ones while memoizing
16
- * deterministic step outputs.
17
- */ export class StepExecutor {
18
- backend;
19
- workflowRunId;
20
- workerId;
21
- cache;
22
- constructor(options){
23
- this.backend = options.backend;
24
- this.workflowRunId = options.workflowRunId;
25
- this.workerId = options.workerId;
26
- this.cache = createStepAttemptCacheFromAttempts(options.attempts);
27
- }
28
- async run(config, fn) {
29
- const { name } = config;
30
- // return cached result if available
31
- const existingAttempt = getCachedStepAttempt(this.cache, name);
32
- if (existingAttempt) {
33
- return existingAttempt.output;
34
- }
35
- // not in cache, create new step attempt
36
- const attempt = await this.backend.createStepAttempt({
37
- workflowRunId: this.workflowRunId,
38
- workerId: this.workerId,
39
- stepName: name,
40
- kind: "function",
41
- config: {},
42
- context: null
43
- });
44
- try {
45
- // execute step function
46
- const result = await fn();
47
- const output = normalizeStepOutput(result);
48
- // mark success
49
- const savedAttempt = await this.backend.completeStepAttempt({
50
- workflowRunId: this.workflowRunId,
51
- stepAttemptId: attempt.id,
52
- workerId: this.workerId,
53
- output
54
- });
55
- // cache result
56
- this.cache = addToStepAttemptCache(this.cache, savedAttempt);
57
- return savedAttempt.output;
58
- } catch (error) {
59
- // mark failure
60
- await this.backend.failStepAttempt({
61
- workflowRunId: this.workflowRunId,
62
- stepAttemptId: attempt.id,
63
- workerId: this.workerId,
64
- error: serializeError(error)
65
- });
66
- throw error;
67
- }
68
- }
69
- async sleep(name, duration) {
70
- // return cached result if this sleep already completed
71
- const existingAttempt = getCachedStepAttempt(this.cache, name);
72
- if (existingAttempt) return;
73
- // create new step attempt for the sleep
74
- const result = calculateSleepResumeAt(duration);
75
- if (!result.ok) {
76
- throw result.error;
77
- }
78
- const resumeAt = result.value;
79
- const context = createSleepContext(resumeAt);
80
- await this.backend.createStepAttempt({
81
- workflowRunId: this.workflowRunId,
82
- workerId: this.workerId,
83
- stepName: name,
84
- kind: "sleep",
85
- config: {},
86
- context
87
- });
88
- // throw sleep signal to trigger postponement
89
- // we do not mark the step as completed here; it will be updated
90
- // when the workflow resumes
91
- throw new SleepSignal(resumeAt);
92
- }
93
- }
19
+ * 외부에서 workflow 상태가 변경되었을 실행을 안전하게 중단하기 위한 에러입니다.
20
+ */
21
+ var WorkflowAbortedError = class extends Error {
22
+ constructor() {
23
+ super("Workflow execution aborted");
24
+ this.name = "WorkflowAbortedError";
25
+ }
26
+ };
27
+ /**
28
+ * Replays prior step attempts and persists new ones while memoizing
29
+ * deterministic step outputs.
30
+ */
31
+ var StepExecutor = class {
32
+ backend;
33
+ workflowRunId;
34
+ workerId;
35
+ signal;
36
+ cache;
37
+ constructor(options) {
38
+ this.backend = options.backend;
39
+ this.workflowRunId = options.workflowRunId;
40
+ this.workerId = options.workerId;
41
+ this.signal = options.signal;
42
+ this.cache = createStepAttemptCacheFromAttempts(options.attempts);
43
+ }
44
+ async run(config, fn) {
45
+ const { name } = config;
46
+ if (this.signal?.aborted) throw new WorkflowAbortedError();
47
+ const existingAttempt = getCachedStepAttempt(this.cache, name);
48
+ if (existingAttempt) return existingAttempt.output;
49
+ const attempt = await this.backend.createStepAttempt({
50
+ workflowRunId: this.workflowRunId,
51
+ workerId: this.workerId,
52
+ stepName: name,
53
+ kind: "function",
54
+ config: {},
55
+ context: null
56
+ });
57
+ try {
58
+ const output = normalizeStepOutput(await fn());
59
+ const savedAttempt = await this.backend.completeStepAttempt({
60
+ workflowRunId: this.workflowRunId,
61
+ stepAttemptId: attempt.id,
62
+ workerId: this.workerId,
63
+ output
64
+ });
65
+ if (!savedAttempt) throw new WorkflowAbortedError();
66
+ this.cache = addToStepAttemptCache(this.cache, savedAttempt);
67
+ return savedAttempt.output;
68
+ } catch (error) {
69
+ if (!await this.backend.failStepAttempt({
70
+ workflowRunId: this.workflowRunId,
71
+ stepAttemptId: attempt.id,
72
+ workerId: this.workerId,
73
+ error: serializeError(error)
74
+ })) throw new WorkflowAbortedError();
75
+ throw error;
76
+ }
77
+ }
78
+ async sleep(name, duration) {
79
+ if (this.signal?.aborted) throw new WorkflowAbortedError();
80
+ if (getCachedStepAttempt(this.cache, name)) return;
81
+ const result = calculateSleepResumeAt(duration);
82
+ if (!result.ok) throw result.error;
83
+ const resumeAt = result.value;
84
+ const context = createSleepContext(resumeAt);
85
+ await this.backend.createStepAttempt({
86
+ workflowRunId: this.workflowRunId,
87
+ workerId: this.workerId,
88
+ stepName: name,
89
+ kind: "sleep",
90
+ config: {},
91
+ context
92
+ });
93
+ throw new SleepSignal(resumeAt);
94
+ }
95
+ };
94
96
  /**
95
- * Execute a workflow run. This is the core application use case that handles:
96
- * - Loading step history
97
- * - Handling sleeping steps
98
- * - Creating the step executor
99
- * - Executing the workflow function
100
- * - Completing, failing, or sleeping the workflow run based on the outcome
101
- * @param params - The execution parameters
102
- */ export async function executeWorkflow(params) {
103
- const { backend, workflowRun, workflowFn, workflowVersion, workerId } = params;
104
- try {
105
- // load all pages of step history
106
- const attempts = [];
107
- let cursor;
108
- do {
109
- const response = await backend.listStepAttempts({
110
- workflowRunId: workflowRun.id,
111
- ...cursor ? {
112
- after: cursor
113
- } : {},
114
- limit: 1000
115
- });
116
- attempts.push(...response.data);
117
- cursor = response.pagination.next ?? undefined;
118
- }while (cursor)
119
- // mark any sleep steps as completed if their sleep duration has elapsed,
120
- // or rethrow SleepSignal if still sleeping
121
- for(let i = 0; i < attempts.length; i++){
122
- const attempt = attempts[i];
123
- if (!attempt) continue;
124
- if (attempt.status === "running" && attempt.kind === "sleep" && attempt.context?.kind === "sleep") {
125
- const now = Date.now();
126
- const resumeAt = new Date(attempt.context.resumeAt);
127
- const resumeAtMs = resumeAt.getTime();
128
- if (now < resumeAtMs) {
129
- // sleep duration HAS NOT elapsed yet, throw signal to put workflow
130
- // back to sleep
131
- throw new SleepSignal(resumeAt);
132
- }
133
- // sleep duration HAS elapsed, mark the step as completed and continue
134
- const completed = await backend.completeStepAttempt({
135
- workflowRunId: workflowRun.id,
136
- stepAttemptId: attempt.id,
137
- workerId,
138
- output: null
139
- });
140
- // update cache w/ completed attempt
141
- attempts[i] = completed;
142
- }
143
- }
144
- // create step executor
145
- const executor = new StepExecutor({
146
- backend,
147
- workflowRunId: workflowRun.id,
148
- workerId,
149
- attempts
150
- });
151
- // execute workflow
152
- const output = await workflowFn({
153
- input: workflowRun.input,
154
- step: executor,
155
- version: workflowVersion
156
- });
157
- // mark success
158
- await backend.completeWorkflowRun({
159
- workflowRunId: workflowRun.id,
160
- workerId,
161
- output: output ?? null
162
- });
163
- } catch (error) {
164
- // handle sleep signal by setting workflow to sleeping status
165
- if (error instanceof SleepSignal) {
166
- await backend.sleepWorkflowRun({
167
- workflowRunId: workflowRun.id,
168
- workerId,
169
- availableAt: error.resumeAt
170
- });
171
- return;
172
- }
173
- // mark failure
174
- await backend.failWorkflowRun({
175
- workflowRunId: workflowRun.id,
176
- workerId,
177
- error: serializeError(error)
178
- });
179
- }
97
+ * Execute a workflow run. This is the core application use case that handles:
98
+ * - Loading step history
99
+ * - Handling sleeping steps
100
+ * - Creating the step executor
101
+ * - Executing the workflow function
102
+ * - Completing, failing, or sleeping the workflow run based on the outcome
103
+ * @param params - The execution parameters
104
+ */
105
+ async function executeWorkflow(params) {
106
+ const { backend, workflowRun, workflowFn, workflowVersion, workerId, retryPolicy, signal } = params;
107
+ try {
108
+ const attempts = [];
109
+ let cursor;
110
+ do {
111
+ const response = await backend.listStepAttempts({
112
+ workflowRunId: workflowRun.id,
113
+ ...cursor ? { after: cursor } : {},
114
+ limit: 1e3
115
+ });
116
+ attempts.push(...response.data);
117
+ cursor = response.pagination.next ?? void 0;
118
+ } while (cursor);
119
+ for (let i = 0; i < attempts.length; i++) {
120
+ const attempt = attempts[i];
121
+ if (!attempt) continue;
122
+ if (attempt.status === "running" && attempt.kind === "sleep" && attempt.context?.kind === "sleep") {
123
+ const now = Date.now();
124
+ const resumeAt = new Date(attempt.context.resumeAt);
125
+ if (now < resumeAt.getTime()) throw new SleepSignal(resumeAt);
126
+ const completed = await backend.completeStepAttempt({
127
+ workflowRunId: workflowRun.id,
128
+ stepAttemptId: attempt.id,
129
+ workerId,
130
+ output: null
131
+ });
132
+ if (!completed) throw new WorkflowAbortedError();
133
+ attempts[i] = completed;
134
+ }
135
+ }
136
+ const executor = new StepExecutor({
137
+ backend,
138
+ workflowRunId: workflowRun.id,
139
+ workerId,
140
+ attempts,
141
+ signal
142
+ });
143
+ const output = await workflowFn({
144
+ input: workflowRun.input,
145
+ step: executor,
146
+ version: workflowVersion
147
+ });
148
+ await backend.completeWorkflowRun({
149
+ workflowRunId: workflowRun.id,
150
+ workerId,
151
+ output: output ?? null
152
+ });
153
+ } catch (error) {
154
+ if (error instanceof SleepSignal) {
155
+ await backend.sleepWorkflowRun({
156
+ workflowRunId: workflowRun.id,
157
+ workerId,
158
+ availableAt: error.resumeAt
159
+ });
160
+ return;
161
+ }
162
+ if (error instanceof WorkflowAbortedError || signal?.aborted) return;
163
+ let forceComplete = false;
164
+ let customDelayMs;
165
+ if (retryPolicy && isDynamicRetryPolicy(retryPolicy)) {
166
+ const serializedError = serializeError(error);
167
+ const decision = retryPolicy.shouldRetry(serializedError, workflowRun.attempts ?? 1);
168
+ if (!decision.shouldRetry) forceComplete = true;
169
+ else customDelayMs = decision.delayMs;
170
+ }
171
+ await backend.failWorkflowRun({
172
+ workflowRunId: workflowRun.id,
173
+ workerId,
174
+ error: serializeError(error),
175
+ forceComplete,
176
+ customDelayMs
177
+ });
178
+ }
180
179
  }
181
180
 
181
+ //#endregion
182
+ export { executeWorkflow };
182
183
  //# sourceMappingURL=execution.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/execution.ts"],"sourcesContent":["import type { Backend } from \"./backend\";\nimport type { DurationString } from \"./core/duration\";\nimport { serializeError } from \"./core/error\";\nimport type { JsonValue } from \"./core/json\";\nimport type { StepAttempt, StepAttemptCache } from \"./core/step\";\nimport {\n addToStepAttemptCache,\n calculateSleepResumeAt,\n createSleepContext,\n createStepAttemptCacheFromAttempts,\n getCachedStepAttempt,\n normalizeStepOutput,\n} from \"./core/step\";\nimport type { WorkflowRun } from \"./core/workflow\";\n\n/**\n * Config for an individual step defined with `step.run()`.\n */\nexport interface StepFunctionConfig {\n /**\n * The name of the step.\n */\n name: string;\n}\n\n/**\n * Represents the API for defining steps within a workflow. Used within a\n * workflow handler to define steps by calling `step.run()`.\n */\nexport interface StepApi {\n run<Output>(config: Readonly<StepFunctionConfig>, fn: StepFunction<Output>): Promise<Output>;\n sleep(name: string, duration: DurationString): Promise<void>;\n}\n\n/**\n * The step definition (defined by the user) that executes user code. Can return\n * undefined (e.g., when using `return;`) which will be converted to null.\n */\nexport type StepFunction<Output> = () => Promise<Output | undefined> | Output | undefined;\n\n/**\n * Params passed to a workflow function for the user to use when defining steps.\n */\nexport interface WorkflowFunctionParams<Input> {\n input: Input;\n step: StepApi;\n version: string | null;\n}\n\n/**\n * The workflow definition's function (defined by the user) that the user uses\n * to define the workflow's steps.\n */\nexport type WorkflowFunction<Input, Output> = (\n params: Readonly<WorkflowFunctionParams<Input>>,\n) => Promise<Output> | Output;\n\n/**\n * Signal thrown when a workflow needs to sleep. Contains the time when the\n * workflow should resume.\n */\nclass SleepSignal extends Error {\n readonly resumeAt: Date;\n\n constructor(resumeAt: Readonly<Date>) {\n super(\"SleepSignal\");\n this.name = \"SleepSignal\";\n this.resumeAt = resumeAt;\n }\n}\n\n/**\n * Configures the options for a StepExecutor.\n */\nexport interface StepExecutorOptions {\n backend: Backend;\n workflowRunId: string;\n workerId: string;\n attempts: StepAttempt[];\n}\n\n/**\n * Replays prior step attempts and persists new ones while memoizing\n * deterministic step outputs.\n */\nexport class StepExecutor implements StepApi {\n private readonly backend: Backend;\n private readonly workflowRunId: string;\n private readonly workerId: string;\n private cache: StepAttemptCache;\n\n constructor(options: Readonly<StepExecutorOptions>) {\n this.backend = options.backend;\n this.workflowRunId = options.workflowRunId;\n this.workerId = options.workerId;\n\n this.cache = createStepAttemptCacheFromAttempts(options.attempts);\n }\n\n async run<Output>(\n config: Readonly<StepFunctionConfig>,\n fn: StepFunction<Output>,\n ): Promise<Output> {\n const { name } = config;\n\n // return cached result if available\n const existingAttempt = getCachedStepAttempt(this.cache, name);\n if (existingAttempt) {\n return existingAttempt.output as Output;\n }\n\n // not in cache, create new step attempt\n const attempt = await this.backend.createStepAttempt({\n workflowRunId: this.workflowRunId,\n workerId: this.workerId,\n stepName: name,\n kind: \"function\",\n config: {},\n context: null,\n });\n\n try {\n // execute step function\n const result = await fn();\n const output = normalizeStepOutput(result);\n\n // mark success\n const savedAttempt = await this.backend.completeStepAttempt({\n workflowRunId: this.workflowRunId,\n stepAttemptId: attempt.id,\n workerId: this.workerId,\n output,\n });\n\n // cache result\n this.cache = addToStepAttemptCache(this.cache, savedAttempt);\n\n return savedAttempt.output as Output;\n } catch (error) {\n // mark failure\n await this.backend.failStepAttempt({\n workflowRunId: this.workflowRunId,\n stepAttemptId: attempt.id,\n workerId: this.workerId,\n error: serializeError(error),\n });\n throw error;\n }\n }\n\n async sleep(name: string, duration: DurationString): Promise<void> {\n // return cached result if this sleep already completed\n const existingAttempt = getCachedStepAttempt(this.cache, name);\n if (existingAttempt) return;\n\n // create new step attempt for the sleep\n const result = calculateSleepResumeAt(duration);\n if (!result.ok) {\n throw result.error;\n }\n const resumeAt = result.value;\n const context = createSleepContext(resumeAt);\n\n await this.backend.createStepAttempt({\n workflowRunId: this.workflowRunId,\n workerId: this.workerId,\n stepName: name,\n kind: \"sleep\",\n config: {},\n context,\n });\n\n // throw sleep signal to trigger postponement\n // we do not mark the step as completed here; it will be updated\n // when the workflow resumes\n throw new SleepSignal(resumeAt);\n }\n}\n\n/**\n * Parameters for the workflow execution use case.\n */\nexport interface ExecuteWorkflowParams {\n backend: Backend;\n workflowRun: WorkflowRun;\n workflowFn: WorkflowFunction<unknown, unknown>;\n workflowVersion: string | null;\n workerId: string;\n}\n\n/**\n * Execute a workflow run. This is the core application use case that handles:\n * - Loading step history\n * - Handling sleeping steps\n * - Creating the step executor\n * - Executing the workflow function\n * - Completing, failing, or sleeping the workflow run based on the outcome\n * @param params - The execution parameters\n */\nexport async function executeWorkflow(params: Readonly<ExecuteWorkflowParams>): Promise<void> {\n const { backend, workflowRun, workflowFn, workflowVersion, workerId } = params;\n\n try {\n // load all pages of step history\n const attempts: StepAttempt[] = [];\n let cursor: string | undefined;\n do {\n const response = await backend.listStepAttempts({\n workflowRunId: workflowRun.id,\n ...(cursor ? { after: cursor } : {}),\n limit: 1000,\n });\n attempts.push(...response.data);\n cursor = response.pagination.next ?? undefined;\n } while (cursor);\n\n // mark any sleep steps as completed if their sleep duration has elapsed,\n // or rethrow SleepSignal if still sleeping\n for (let i = 0; i < attempts.length; i++) {\n const attempt = attempts[i];\n if (!attempt) continue;\n\n if (\n attempt.status === \"running\" &&\n attempt.kind === \"sleep\" &&\n attempt.context?.kind === \"sleep\"\n ) {\n const now = Date.now();\n const resumeAt = new Date(attempt.context.resumeAt);\n const resumeAtMs = resumeAt.getTime();\n\n if (now < resumeAtMs) {\n // sleep duration HAS NOT elapsed yet, throw signal to put workflow\n // back to sleep\n throw new SleepSignal(resumeAt);\n }\n\n // sleep duration HAS elapsed, mark the step as completed and continue\n const completed = await backend.completeStepAttempt({\n workflowRunId: workflowRun.id,\n stepAttemptId: attempt.id,\n workerId,\n output: null,\n });\n\n // update cache w/ completed attempt\n attempts[i] = completed;\n }\n }\n\n // create step executor\n const executor = new StepExecutor({\n backend,\n workflowRunId: workflowRun.id,\n workerId,\n attempts,\n });\n\n // execute workflow\n const output = await workflowFn({\n input: workflowRun.input as unknown,\n step: executor,\n version: workflowVersion,\n });\n\n // mark success\n await backend.completeWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n output: (output ?? null) as JsonValue,\n });\n } catch (error) {\n // handle sleep signal by setting workflow to sleeping status\n if (error instanceof SleepSignal) {\n await backend.sleepWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n availableAt: error.resumeAt,\n });\n\n return;\n }\n\n // mark failure\n await backend.failWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n error: serializeError(error),\n });\n }\n}\n"],"names":["serializeError","addToStepAttemptCache","calculateSleepResumeAt","createSleepContext","createStepAttemptCacheFromAttempts","getCachedStepAttempt","normalizeStepOutput","SleepSignal","Error","resumeAt","name","StepExecutor","backend","workflowRunId","workerId","cache","options","attempts","run","config","fn","existingAttempt","output","attempt","createStepAttempt","stepName","kind","context","result","savedAttempt","completeStepAttempt","stepAttemptId","id","error","failStepAttempt","sleep","duration","ok","value","executeWorkflow","params","workflowRun","workflowFn","workflowVersion","cursor","response","listStepAttempts","after","limit","push","data","pagination","next","undefined","i","length","status","now","Date","resumeAtMs","getTime","completed","executor","input","step","version","completeWorkflowRun","sleepWorkflowRun","availableAt","failWorkflowRun"],"mappings":"AAEA,SAASA,cAAc,QAAQ,kBAAe;AAG9C,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,kBAAkB,EAClBC,kCAAkC,EAClCC,oBAAoB,EACpBC,mBAAmB,QACd,iBAAc;AA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A6D;QAC7D,IAAIA,iBAAiB1B,aAAa;YAChC,MAAMK,QAAQuD,gBAAgB,CAAC;gBAC7BtD,eAAe4B,YAAYT,EAAE;gBAC7BlB;gBACAsD,aAAanC,MAAMxB,QAAQ;YAC7B;YAEA;QACF;QAEA,eAAe;QACf,MAAMG,QAAQyD,eAAe,CAAC;YAC5BxD,eAAe4B,YAAYT,EAAE;YAC7BlB;YACAmB,OAAOjC,eAAeiC;QACxB;IACF;AACF"}
1
+ {"version":3,"file":"execution.js","names":["attempts: StepAttempt[]","cursor: string | undefined","customDelayMs: number | undefined"],"sources":["../src/execution.ts"],"sourcesContent":["import { type Backend } from \"./backend\";\nimport { type DurationString } from \"./core/duration\";\nimport { serializeError } from \"./core/error\";\nimport { type JsonValue } from \"./core/json\";\nimport { isDynamicRetryPolicy } from \"./core/retry\";\nimport { type RetryPolicy } from \"./core/retry\";\nimport { type StepAttempt, type StepAttemptCache } from \"./core/step\";\nimport {\n addToStepAttemptCache,\n calculateSleepResumeAt,\n createSleepContext,\n createStepAttemptCacheFromAttempts,\n getCachedStepAttempt,\n normalizeStepOutput,\n} from \"./core/step\";\nimport { type WorkflowRun } from \"./core/workflow\";\n\n/**\n * Config for an individual step defined with `step.run()`.\n */\nexport interface StepFunctionConfig {\n /**\n * The name of the step.\n */\n name: string;\n}\n\n/**\n * Represents the API for defining steps within a workflow. Used within a\n * workflow handler to define steps by calling `step.run()`.\n */\nexport interface StepApi {\n run<Output>(config: Readonly<StepFunctionConfig>, fn: StepFunction<Output>): Promise<Output>;\n sleep(name: string, duration: DurationString): Promise<void>;\n}\n\n/**\n * The step definition (defined by the user) that executes user code. Can return\n * undefined (e.g., when using `return;`) which will be converted to null.\n */\nexport type StepFunction<Output> = () => Promise<Output | undefined> | Output | undefined;\n\n/**\n * Params passed to a workflow function for the user to use when defining steps.\n */\nexport interface WorkflowFunctionParams<Input> {\n input: Input;\n step: StepApi;\n version: string | null;\n}\n\n/**\n * The workflow definition's function (defined by the user) that the user uses\n * to define the workflow's steps.\n */\nexport type WorkflowFunction<Input, Output> = (\n params: Readonly<WorkflowFunctionParams<Input>>,\n) => Promise<Output> | Output;\n\n/**\n * Signal thrown when a workflow needs to sleep. Contains the time when the\n * workflow should resume.\n */\nclass SleepSignal extends Error {\n readonly resumeAt: Date;\n\n constructor(resumeAt: Readonly<Date>) {\n super(\"SleepSignal\");\n this.name = \"SleepSignal\";\n this.resumeAt = resumeAt;\n }\n}\n\n/**\n * 외부에서 workflow 상태가 변경되었을 때 실행을 안전하게 중단하기 위한 에러입니다.\n */\nclass WorkflowAbortedError extends Error {\n constructor() {\n super(\"Workflow execution aborted\");\n this.name = \"WorkflowAbortedError\";\n }\n}\n\n/**\n * Configures the options for a StepExecutor.\n */\nexport interface StepExecutorOptions {\n backend: Backend;\n workflowRunId: string;\n workerId: string;\n attempts: StepAttempt[];\n signal?: AbortSignal;\n}\n\n/**\n * Replays prior step attempts and persists new ones while memoizing\n * deterministic step outputs.\n */\nexport class StepExecutor implements StepApi {\n private readonly backend: Backend;\n private readonly workflowRunId: string;\n private readonly workerId: string;\n private readonly signal?: AbortSignal;\n private cache: StepAttemptCache;\n\n constructor(options: Readonly<StepExecutorOptions>) {\n this.backend = options.backend;\n this.workflowRunId = options.workflowRunId;\n this.workerId = options.workerId;\n this.signal = options.signal;\n\n this.cache = createStepAttemptCacheFromAttempts(options.attempts);\n }\n\n async run<Output>(\n config: Readonly<StepFunctionConfig>,\n fn: StepFunction<Output>,\n ): Promise<Output> {\n const { name } = config;\n if (this.signal?.aborted) {\n throw new WorkflowAbortedError();\n }\n\n // return cached result if available\n const existingAttempt = getCachedStepAttempt(this.cache, name);\n if (existingAttempt) {\n return existingAttempt.output as Output;\n }\n\n // not in cache, create new step attempt\n const attempt = await this.backend.createStepAttempt({\n workflowRunId: this.workflowRunId,\n workerId: this.workerId,\n stepName: name,\n kind: \"function\",\n config: {},\n context: null,\n });\n\n try {\n // execute step function\n const result = await fn();\n const output = normalizeStepOutput(result);\n\n // mark success — null이면 외부에서 워크플로우 상태가 변경된 것입니다(pause/cancel).\n const savedAttempt = await this.backend.completeStepAttempt({\n workflowRunId: this.workflowRunId,\n stepAttemptId: attempt.id,\n workerId: this.workerId,\n output,\n });\n if (!savedAttempt) {\n throw new WorkflowAbortedError();\n }\n\n // cache result\n this.cache = addToStepAttemptCache(this.cache, savedAttempt);\n\n return savedAttempt.output as Output;\n } catch (error) {\n // mark failure — null이면 외부에서 워크플로우 상태가 변경된 것입니다(pause/cancel).\n const failed = await this.backend.failStepAttempt({\n workflowRunId: this.workflowRunId,\n stepAttemptId: attempt.id,\n workerId: this.workerId,\n error: serializeError(error),\n });\n if (!failed) {\n throw new WorkflowAbortedError();\n }\n\n throw error;\n }\n }\n\n async sleep(name: string, duration: DurationString): Promise<void> {\n if (this.signal?.aborted) {\n throw new WorkflowAbortedError();\n }\n\n // return cached result if this sleep already completed\n const existingAttempt = getCachedStepAttempt(this.cache, name);\n if (existingAttempt) return;\n\n // create new step attempt for the sleep\n const result = calculateSleepResumeAt(duration);\n if (!result.ok) {\n throw result.error;\n }\n const resumeAt = result.value;\n const context = createSleepContext(resumeAt);\n\n await this.backend.createStepAttempt({\n workflowRunId: this.workflowRunId,\n workerId: this.workerId,\n stepName: name,\n kind: \"sleep\",\n config: {},\n context,\n });\n\n // throw sleep signal to trigger postponement\n // we do not mark the step as completed here; it will be updated\n // when the workflow resumes\n throw new SleepSignal(resumeAt);\n }\n}\n\n/**\n * Parameters for the workflow execution use case.\n */\nexport interface ExecuteWorkflowParams {\n backend: Backend;\n workflowRun: WorkflowRun;\n workflowFn: WorkflowFunction<unknown, unknown>;\n workflowVersion: string | null;\n workerId: string;\n retryPolicy?: RetryPolicy;\n signal?: AbortSignal;\n}\n\n/**\n * Execute a workflow run. This is the core application use case that handles:\n * - Loading step history\n * - Handling sleeping steps\n * - Creating the step executor\n * - Executing the workflow function\n * - Completing, failing, or sleeping the workflow run based on the outcome\n * @param params - The execution parameters\n */\nexport async function executeWorkflow(params: Readonly<ExecuteWorkflowParams>): Promise<void> {\n const { backend, workflowRun, workflowFn, workflowVersion, workerId, retryPolicy, signal } =\n params;\n\n try {\n // load all pages of step history\n const attempts: StepAttempt[] = [];\n let cursor: string | undefined;\n do {\n const response = await backend.listStepAttempts({\n workflowRunId: workflowRun.id,\n ...(cursor ? { after: cursor } : {}),\n limit: 1000,\n });\n attempts.push(...response.data);\n cursor = response.pagination.next ?? undefined;\n } while (cursor);\n\n // mark any sleep steps as completed if their sleep duration has elapsed,\n // or rethrow SleepSignal if still sleeping\n for (let i = 0; i < attempts.length; i++) {\n const attempt = attempts[i];\n if (!attempt) continue;\n\n if (\n attempt.status === \"running\" &&\n attempt.kind === \"sleep\" &&\n attempt.context?.kind === \"sleep\"\n ) {\n const now = Date.now();\n const resumeAt = new Date(attempt.context.resumeAt);\n const resumeAtMs = resumeAt.getTime();\n\n if (now < resumeAtMs) {\n // sleep duration HAS NOT elapsed yet, throw signal to put workflow\n // back to sleep\n throw new SleepSignal(resumeAt);\n }\n\n // sleep duration HAS elapsed, mark the step as completed and continue\n const completed = await backend.completeStepAttempt({\n workflowRunId: workflowRun.id,\n stepAttemptId: attempt.id,\n workerId,\n output: null,\n });\n if (!completed) {\n throw new WorkflowAbortedError();\n }\n\n // update cache w/ completed attempt\n attempts[i] = completed;\n }\n }\n\n // create step executor\n const executor = new StepExecutor({\n backend,\n workflowRunId: workflowRun.id,\n workerId,\n attempts,\n signal,\n });\n\n // execute workflow\n const output = await workflowFn({\n input: workflowRun.input as unknown,\n step: executor,\n version: workflowVersion,\n });\n\n // mark success\n await backend.completeWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n output: (output ?? null) as JsonValue,\n });\n } catch (error) {\n // handle sleep signal by setting workflow to sleeping status\n if (error instanceof SleepSignal) {\n await backend.sleepWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n availableAt: error.resumeAt,\n });\n\n return;\n }\n\n // heartbeat 실패로 abort된 경우, failWorkflowRun을 호출하지 않고 조용히 종료합니다.\n if (error instanceof WorkflowAbortedError || signal?.aborted) {\n return;\n }\n\n // claimWorkflowRun에서 이미 attempts가 증가된 상태입니다.\n let forceComplete = false;\n let customDelayMs: number | undefined;\n if (retryPolicy && isDynamicRetryPolicy(retryPolicy)) {\n const serializedError = serializeError(error);\n const decision = retryPolicy.shouldRetry(serializedError, workflowRun.attempts ?? 1);\n if (!decision.shouldRetry) {\n forceComplete = true;\n } else {\n customDelayMs = decision.delayMs;\n }\n }\n\n await backend.failWorkflowRun({\n workflowRunId: workflowRun.id,\n workerId,\n error: serializeError(error),\n forceComplete,\n customDelayMs,\n });\n }\n}\n"],"mappings":";;;;;;;;;AA+DA,IAAM,cAAN,cAA0B,MAAM;CAC9B,AAAS;CAET,YAAY,UAA0B;AACpC,QAAM,cAAc;AACpB,OAAK,OAAO;AACZ,OAAK,WAAW;;;;;;AAOpB,IAAM,uBAAN,cAAmC,MAAM;CACvC,cAAc;AACZ,QAAM,6BAA6B;AACnC,OAAK,OAAO;;;;;;;AAmBhB,IAAa,eAAb,MAA6C;CAC3C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ;CAER,YAAY,SAAwC;AAClD,OAAK,UAAU,QAAQ;AACvB,OAAK,gBAAgB,QAAQ;AAC7B,OAAK,WAAW,QAAQ;AACxB,OAAK,SAAS,QAAQ;AAEtB,OAAK,QAAQ,mCAAmC,QAAQ,SAAS;;CAGnE,MAAM,IACJ,QACA,IACiB;EACjB,MAAM,EAAE,SAAS;AACjB,MAAI,KAAK,QAAQ,QACf,OAAM,IAAI,sBAAsB;EAIlC,MAAM,kBAAkB,qBAAqB,KAAK,OAAO,KAAK;AAC9D,MAAI,gBACF,QAAO,gBAAgB;EAIzB,MAAM,UAAU,MAAM,KAAK,QAAQ,kBAAkB;GACnD,eAAe,KAAK;GACpB,UAAU,KAAK;GACf,UAAU;GACV,MAAM;GACN,QAAQ,EAAE;GACV,SAAS;GACV,CAAC;AAEF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,MAAM;GAC5B;GACA;GACD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- export type { OpenWorkflowOptions } from "./client";
2
- export { declareWorkflow, OpenWorkflow } from "./client";
3
- export type { OpenWorkflowConfig, WorkerConfig } from "./config";
4
- export { defineConfig } from "./config";
5
- export { BackendPostgres } from "./database/backend";
6
- export type { WorkerOptions } from "./worker";
7
- export { Worker } from "./worker";
8
- //# sourceMappingURL=index.d.ts.map
1
+ import { Worker, WorkerOptions } from "./worker.js";
2
+ import { OpenWorkflow, OpenWorkflowOptions, declareWorkflow } from "./client.js";
3
+ import { OpenWorkflowConfig, WorkerConfig, defineConfig } from "./config.js";
4
+ import { BackendPostgres } from "./database/backend.js";
5
+ export { BackendPostgres, OpenWorkflow, type OpenWorkflowConfig, type OpenWorkflowOptions, Worker, type WorkerConfig, type WorkerOptions, declareWorkflow, defineConfig };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { declareWorkflow, OpenWorkflow } from "./client.js";
2
- export { defineConfig } from "./config.js";
3
- export { BackendPostgres } from "./database/backend.js";
4
- export { Worker } from "./worker.js";
1
+ import { Worker } from "./worker.js";
2
+ import { OpenWorkflow, declareWorkflow } from "./client.js";
3
+ import { defineConfig } from "./config.js";
4
+ import { BackendPostgres } from "./database/backend.js";
5
5
 
6
- //# sourceMappingURL=index.js.map
6
+ export { BackendPostgres, OpenWorkflow, Worker, declareWorkflow, defineConfig };
@@ -1,12 +1,12 @@
1
- export * from "./backend";
2
- export type * from "./client";
3
- export { loadConfig } from "./config";
4
- export type { DurationString } from "./core/duration";
5
- export type { JsonValue } from "./core/json";
6
- export { DEFAULT_RETRY_POLICY } from "./core/retry";
7
- export type { StandardSchemaV1 } from "./core/schema";
8
- export type { StepAttempt } from "./core/step";
9
- export type { SchemaInput, SchemaOutput, WorkflowRun } from "./core/workflow";
10
- export type { StepApi, WorkflowFunction } from "./execution";
11
- export type { WorkflowSpec } from "./workflow";
12
- //# sourceMappingURL=internal.d.ts.map
1
+ import { JsonValue } from "./core/json.js";
2
+ import { DEFAULT_RETRY_POLICY, DynamicRetryPolicy, MergedDynamicRetryPolicy, MergedRetryPolicy, MergedStaticRetryPolicy, RetryDecision, RetryDecisionFn, RetryPolicy, SerializableRetryPolicy, StaticRetryPolicy, calculateRetryDelayMs, isDynamicRetryPolicy, isStaticRetryPolicy, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy } from "./core/retry.js";
3
+ import { DurationString } from "./core/duration.js";
4
+ import { StepAttempt } from "./core/step.js";
5
+ import { StandardSchemaV1 } from "./core/schema.js";
6
+ import { SchemaInput, SchemaOutput, WorkflowRun } from "./core/workflow.js";
7
+ import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CompleteStepAttemptParams, CompleteWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, DEFAULT_NAMESPACE_ID, ExtendWorkflowRunLeaseParams, FailStepAttemptParams, FailWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, PaginationOptions, PauseWorkflowRunParams, ResumeWorkflowRunParams, SleepWorkflowRunParams } from "./backend.js";
8
+ import { StepApi, WorkflowFunction } from "./execution.js";
9
+ import { WorkflowSpec } from "./workflow.js";
10
+ import { OpenWorkflow, OpenWorkflowOptions, RunnableWorkflow, WorkflowHandleOptions, WorkflowRunHandle, WorkflowRunOptions, declareWorkflow } from "./client.js";
11
+ import { loadConfig } from "./config.js";
12
+ export { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CompleteStepAttemptParams, CompleteWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, DEFAULT_NAMESPACE_ID, DEFAULT_RETRY_POLICY, type DurationString, type DynamicRetryPolicy, ExtendWorkflowRunLeaseParams, FailStepAttemptParams, FailWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, type JsonValue, ListStepAttemptsParams, ListWorkflowRunsParams, type MergedDynamicRetryPolicy, type MergedRetryPolicy, type MergedStaticRetryPolicy, OpenWorkflow, OpenWorkflowOptions, PaginatedResponse, PaginationOptions, PauseWorkflowRunParams, ResumeWorkflowRunParams, type RetryDecision, type RetryDecisionFn, type RetryPolicy, RunnableWorkflow, type SchemaInput, type SchemaOutput, type SerializableRetryPolicy, SleepWorkflowRunParams, type StandardSchemaV1, type StaticRetryPolicy, type StepApi, type StepAttempt, type WorkflowFunction, WorkflowHandleOptions, type WorkflowRun, WorkflowRunHandle, WorkflowRunOptions, type WorkflowSpec, calculateRetryDelayMs, declareWorkflow, isDynamicRetryPolicy, isStaticRetryPolicy, loadConfig, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy };
package/dist/internal.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./backend.js";
2
- export { loadConfig } from "./config.js";
3
- export { DEFAULT_RETRY_POLICY } from "./core/retry.js";
1
+ import { DEFAULT_RETRY_POLICY, calculateRetryDelayMs, isDynamicRetryPolicy, isStaticRetryPolicy, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy } from "./core/retry.js";
2
+ import { loadConfig } from "./config.js";
3
+ import { DEFAULT_NAMESPACE_ID } from "./backend.js";
4
4
 
5
- //# sourceMappingURL=internal.js.map
5
+ export { DEFAULT_NAMESPACE_ID, DEFAULT_RETRY_POLICY, calculateRetryDelayMs, isDynamicRetryPolicy, isStaticRetryPolicy, loadConfig, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy };