@hatchet-dev/typescript-sdk 1.15.2 → 1.17.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 (202) hide show
  1. package/README.md +14 -2
  2. package/clients/admin/admin-client.d.ts +2 -2
  3. package/clients/admin/admin-client.js +8 -9
  4. package/clients/dispatcher/action-listener.d.ts +3 -6
  5. package/clients/dispatcher/action-listener.js +54 -23
  6. package/clients/dispatcher/dispatcher-client.js +5 -8
  7. package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
  8. package/clients/event/event-client.d.ts +2 -2
  9. package/clients/event/event-client.js +5 -11
  10. package/clients/hatchet-client/hatchet-logger.js +8 -17
  11. package/clients/listeners/durable-listener/durable-listener-client.d.ts +115 -15
  12. package/clients/listeners/durable-listener/durable-listener-client.js +769 -19
  13. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +11 -22
  14. package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
  15. package/clients/listeners/run-listener/child-listener-client.js +34 -30
  16. package/clients/listeners/run-listener/pooled-child-listener-client.js +9 -19
  17. package/clients/rest/generated/Api.d.ts +25 -1
  18. package/clients/rest/generated/Api.js +20 -0
  19. package/clients/rest/generated/data-contracts.d.ts +60 -1
  20. package/clients/rest/generated/data-contracts.js +9 -1
  21. package/legacy/examples/affinity-workers.js +2 -3
  22. package/legacy/examples/byo-logger.js +0 -2
  23. package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
  24. package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
  25. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
  26. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
  27. package/legacy/examples/example-event.js +0 -3
  28. package/legacy/examples/logger.js +0 -1
  29. package/legacy/examples/sticky-worker-with-check.js +0 -1
  30. package/legacy/examples/sticky-worker.js +0 -1
  31. package/legacy/legacy-client.js +2 -2
  32. package/legacy/legacy-transformer.js +2 -4
  33. package/legacy/step.d.ts +16 -16
  34. package/legacy/step.js +8 -17
  35. package/legacy/workflow.d.ts +81 -81
  36. package/package.json +20 -29
  37. package/protoc/dispatcher/dispatcher.d.ts +20 -0
  38. package/protoc/dispatcher/dispatcher.js +136 -2
  39. package/protoc/v1/dispatcher.d.ts +168 -0
  40. package/protoc/v1/dispatcher.js +1920 -1
  41. package/protoc/v1/shared/trigger.d.ts +89 -0
  42. package/protoc/v1/shared/trigger.js +493 -0
  43. package/protoc/v1/workflows.d.ts +34 -34
  44. package/protoc/v1/workflows.js +252 -200
  45. package/protoc/workflows/workflows.d.ts +2 -75
  46. package/protoc/workflows/workflows.js +16 -491
  47. package/util/abort-error.d.ts +15 -1
  48. package/util/abort-error.js +30 -5
  49. package/util/config-loader/config-loader.js +4 -3
  50. package/util/config-loader/token.js +9 -2
  51. package/util/errors/eviction-not-supported-error.d.ts +5 -0
  52. package/util/errors/eviction-not-supported-error.js +18 -0
  53. package/util/errors/hatchet-error.d.ts +9 -1
  54. package/util/errors/hatchet-error.js +23 -2
  55. package/util/errors/non-determinism-error.d.ts +7 -0
  56. package/util/errors/non-determinism-error.js +21 -0
  57. package/util/errors/task-run-terminated-error.d.ts +6 -0
  58. package/util/errors/task-run-terminated-error.js +15 -0
  59. package/util/grpc-error.d.ts +9 -0
  60. package/util/grpc-error.js +25 -0
  61. package/util/hatchet-promise/hatchet-promise.d.ts +6 -1
  62. package/util/hatchet-promise/hatchet-promise.js +16 -2
  63. package/util/logger/logger.js +0 -1
  64. package/util/parse.d.ts +1 -1
  65. package/util/parse.js +4 -2
  66. package/util/retrier.js +2 -3
  67. package/util/sleep.d.ts +3 -2
  68. package/util/sleep.js +6 -4
  69. package/util/workflow-run-ref.js +5 -3
  70. package/v1/client/admin.d.ts +2 -2
  71. package/v1/client/admin.js +2 -6
  72. package/v1/client/client.d.ts +7 -11
  73. package/v1/client/client.interface.d.ts +5 -8
  74. package/v1/client/client.js +34 -40
  75. package/v1/client/duration.d.ts +11 -1
  76. package/v1/client/duration.js +44 -0
  77. package/v1/client/features/cel.js +1 -1
  78. package/v1/client/features/crons.js +2 -2
  79. package/v1/client/features/index.d.ts +5 -0
  80. package/v1/client/features/index.js +5 -0
  81. package/v1/client/features/logs.d.ts +37 -0
  82. package/v1/client/features/logs.js +46 -0
  83. package/v1/client/features/runs.d.ts +16 -3
  84. package/v1/client/features/runs.js +38 -4
  85. package/v1/client/features/schedules.js +4 -4
  86. package/v1/client/features/webhooks.js +4 -2
  87. package/v1/client/features/workflows.js +1 -1
  88. package/v1/client/worker/context.d.ts +101 -6
  89. package/v1/client/worker/context.js +257 -44
  90. package/v1/client/worker/deprecated/deprecation.js +8 -4
  91. package/v1/client/worker/deprecated/index.d.ts +1 -1
  92. package/v1/client/worker/deprecated/index.js +2 -1
  93. package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
  94. package/v1/client/worker/deprecated/legacy-worker.js +33 -24
  95. package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
  96. package/v1/client/worker/deprecated/pre-eviction.js +37 -0
  97. package/v1/client/worker/engine-version.d.ts +5 -0
  98. package/v1/client/worker/engine-version.js +14 -0
  99. package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
  100. package/v1/client/worker/eviction/eviction-cache.js +139 -0
  101. package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
  102. package/v1/client/worker/eviction/eviction-manager.js +132 -0
  103. package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
  104. package/v1/client/worker/eviction/eviction-policy.js +8 -0
  105. package/v1/client/worker/eviction/index.d.ts +3 -0
  106. package/v1/client/worker/eviction/index.js +11 -0
  107. package/v1/client/worker/health-server.js +3 -3
  108. package/v1/client/worker/slot-utils.js +0 -3
  109. package/v1/client/worker/worker-internal.d.ts +23 -4
  110. package/v1/client/worker/worker-internal.js +216 -148
  111. package/v1/client/worker/worker.d.ts +1 -0
  112. package/v1/client/worker/worker.js +34 -0
  113. package/v1/conditions/base.js +0 -1
  114. package/v1/conditions/index.js +2 -4
  115. package/v1/conditions/sleep-condition.js +2 -1
  116. package/v1/conditions/transformer.js +2 -1
  117. package/v1/declaration.d.ts +6 -4
  118. package/v1/declaration.js +20 -7
  119. package/v1/examples/__e2e__/harness.d.ts +5 -0
  120. package/v1/examples/__e2e__/harness.js +17 -3
  121. package/v1/examples/affinity/affinity-workers.js +0 -1
  122. package/v1/examples/bulk_operations/workflow.js +0 -1
  123. package/v1/examples/cancellation/run.js +0 -1
  124. package/v1/examples/cancellations/run.js +0 -1
  125. package/v1/examples/child_workflows/run.js +0 -2
  126. package/v1/examples/child_workflows/workflow.js +0 -1
  127. package/v1/examples/concurrency-rr/load.js +0 -1
  128. package/v1/examples/concurrency-rr/run.js +0 -3
  129. package/v1/examples/concurrency_limit_rr/load.js +0 -1
  130. package/v1/examples/concurrency_limit_rr/run.js +0 -3
  131. package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
  132. package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
  133. package/v1/examples/conditions/event.js +0 -1
  134. package/v1/examples/conditions/run.js +0 -1
  135. package/v1/examples/dag/run.js +0 -1
  136. package/v1/examples/dag_match_condition/event.js +0 -1
  137. package/v1/examples/dag_match_condition/run.js +0 -1
  138. package/v1/examples/deep/run.js +0 -2
  139. package/v1/examples/durable/workflow.d.ts +57 -0
  140. package/v1/examples/durable/workflow.js +164 -10
  141. package/v1/examples/durable-event/event.js +0 -1
  142. package/v1/examples/durable-event/run.js +0 -2
  143. package/v1/examples/durable-event/workflow.js +2 -7
  144. package/v1/examples/durable-sleep/event.js +0 -1
  145. package/v1/examples/durable-sleep/run.js +0 -2
  146. package/v1/examples/durable_event/event.js +0 -1
  147. package/v1/examples/durable_event/run.js +0 -2
  148. package/v1/examples/durable_event/workflow.d.ts +1 -0
  149. package/v1/examples/durable_event/workflow.js +4 -9
  150. package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
  151. package/v1/examples/durable_eviction/capacity-worker.js +31 -0
  152. package/v1/examples/durable_eviction/worker.d.ts +1 -0
  153. package/v1/examples/durable_eviction/worker.js +34 -0
  154. package/v1/examples/durable_eviction/workflow.d.ts +44 -0
  155. package/v1/examples/durable_eviction/workflow.js +129 -0
  156. package/v1/examples/durable_sleep/event.js +0 -1
  157. package/v1/examples/durable_sleep/run.js +0 -2
  158. package/v1/examples/e2e-worker.js +42 -19
  159. package/v1/examples/events/event.js +0 -1
  160. package/v1/examples/high-memory/run.js +0 -1
  161. package/v1/examples/inferred-typing/run.js +0 -1
  162. package/v1/examples/landing_page/durable-excution.js +0 -1
  163. package/v1/examples/landing_page/queues.js +0 -1
  164. package/v1/examples/legacy/run.js +0 -1
  165. package/v1/examples/logger/byo-logger.js +0 -2
  166. package/v1/examples/logger/logger.js +0 -1
  167. package/v1/examples/logging/byo-logger.js +0 -2
  168. package/v1/examples/logging/logger.js +0 -1
  169. package/v1/examples/middleware/recipes.js +3 -1
  170. package/v1/examples/migration-guides/mergent.js +2 -1
  171. package/v1/examples/multiple_wf_concurrency/run.js +0 -3
  172. package/v1/examples/non_retryable/run.js +0 -1
  173. package/v1/examples/on_event/event.js +0 -1
  174. package/v1/examples/on_failure/run.js +0 -1
  175. package/v1/examples/on_failure/workflow.js +0 -1
  176. package/v1/examples/on_success/run.js +0 -1
  177. package/v1/examples/on_success/workflow.js +0 -1
  178. package/v1/examples/priority/run.js +0 -1
  179. package/v1/examples/priority/workflow.js +0 -1
  180. package/v1/examples/retries/run.js +0 -1
  181. package/v1/examples/retries/workflow.js +0 -1
  182. package/v1/examples/simple/bulk.js +0 -1
  183. package/v1/examples/simple/cron.js +0 -2
  184. package/v1/examples/simple/delay.js +0 -1
  185. package/v1/examples/simple/enqueue.js +0 -2
  186. package/v1/examples/simple/run.js +0 -1
  187. package/v1/examples/simple/schedule.js +0 -1
  188. package/v1/examples/simple/workflow-with-child.js +10 -4
  189. package/v1/examples/sticky/run.js +0 -1
  190. package/v1/examples/sticky/workflow.js +0 -1
  191. package/v1/examples/streaming/nextjs-proxy.js +0 -1
  192. package/v1/examples/streaming/run.js +0 -1
  193. package/v1/examples/timeout/run.js +0 -1
  194. package/v1/examples/timeouts/run.js +0 -1
  195. package/v1/index.d.ts +5 -0
  196. package/v1/index.js +10 -0
  197. package/v1/parent-run-context-vars.d.ts +6 -0
  198. package/v1/slot-types.js +0 -1
  199. package/v1/task.d.ts +10 -2
  200. package/v1/task.js +2 -1
  201. package/version.d.ts +1 -1
  202. package/version.js +1 -1
@@ -8,10 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
13
- /* eslint-disable no-console */
15
+ exports.durableSpawnDag = exports.dagChildWorkflow = exports.memoNowCaching = exports.durableReplayReset = exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = exports.REPLAY_RESET_SLEEP_SECONDS = exports.durableNonDeterminism = exports.durableWithExplicitSpawn = exports.durableSleepEventSpawn = exports.durableWithBulkSpawn = exports.durableWithSpawn = exports.spawnChildTask = exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
14
16
  const conditions_1 = require("../../conditions");
17
+ const non_determinism_error_1 = require("../../../util/errors/non-determinism-error");
18
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
15
19
  const hatchet_client_1 = require("../hatchet-client");
16
20
  exports.EVENT_KEY = 'durable-example:event';
17
21
  exports.SLEEP_TIME_SECONDS = 2;
@@ -32,12 +36,16 @@ exports.durableWorkflow.durableTask({
32
36
  executionTimeout: '10m',
33
37
  fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
38
  console.log('Waiting for sleep');
35
- yield ctx.sleepFor(exports.SLEEP_TIME);
39
+ const sleepResult = yield ctx.sleepFor(exports.SLEEP_TIME);
36
40
  console.log('Sleep finished');
37
41
  console.log('Waiting for event');
38
- yield ctx.waitFor({ eventKey: exports.EVENT_KEY });
42
+ const event = yield ctx.waitForEvent(exports.EVENT_KEY, 'true');
39
43
  console.log('Event received');
40
- return { status: 'success' };
44
+ return {
45
+ status: 'success',
46
+ event: event,
47
+ sleep_duration_ms: sleepResult.durationMs,
48
+ };
41
49
  }),
42
50
  });
43
51
  function extractKeyAndEventId(waitResult) {
@@ -45,12 +53,12 @@ function extractKeyAndEventId(waitResult) {
45
53
  // The shape is typically `{ [readableDataKey]: { [eventId]: ... } }`.
46
54
  const obj = waitResult;
47
55
  if (obj && typeof obj === 'object') {
48
- const key = Object.keys(obj)[0];
56
+ const [key] = Object.keys(obj);
49
57
  const inner = obj[key];
50
- if (inner && typeof inner === 'object') {
51
- const eventId = Object.keys(inner)[0];
58
+ if (inner && typeof inner === 'object' && !Array.isArray(inner)) {
59
+ const [eventId] = Object.keys(inner);
52
60
  if (eventId) {
53
- return { key: 'CREATE', eventId };
61
+ return { key, eventId };
54
62
  }
55
63
  }
56
64
  if (key) {
@@ -109,8 +117,154 @@ exports.waitForSleepTwice = hatchet_client_1.hatchet.durableTask({
109
117
  return { runtime: Math.round((Date.now() - start) / 1000) };
110
118
  }
111
119
  catch (e) {
112
- // treat cancellation as a successful completion for parity with Python sample
113
120
  return { runtime: -1 };
114
121
  }
115
122
  }),
116
123
  });
124
+ // --- Spawn child from durable task ---
125
+ exports.spawnChildTask = hatchet_client_1.hatchet.task({
126
+ name: 'spawn-child-task',
127
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
128
+ var _a;
129
+ return { message: `hello from child ${(_a = input.n) !== null && _a !== void 0 ? _a : 1}` };
130
+ }),
131
+ });
132
+ exports.durableWithSpawn = hatchet_client_1.hatchet.durableTask({
133
+ name: 'durable-with-spawn',
134
+ executionTimeout: '10s',
135
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
136
+ const childResult = yield exports.spawnChildTask.run({});
137
+ return { child_output: childResult };
138
+ }),
139
+ });
140
+ exports.durableWithBulkSpawn = hatchet_client_1.hatchet.durableTask({
141
+ name: 'durable-with-bulk-spawn',
142
+ executionTimeout: '10m',
143
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
144
+ var _a;
145
+ const n = (_a = input.n) !== null && _a !== void 0 ? _a : 10;
146
+ const inputs = Array.from({ length: n }, (_, i) => ({ n: i }));
147
+ const childResults = yield exports.spawnChildTask.run(inputs);
148
+ return { child_outputs: childResults };
149
+ }),
150
+ });
151
+ exports.durableSleepEventSpawn = hatchet_client_1.hatchet.durableTask({
152
+ name: 'durable-sleep-event-spawn',
153
+ executionTimeout: '10m',
154
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
155
+ const start = Date.now();
156
+ yield ctx.sleepFor(exports.SLEEP_TIME);
157
+ yield ctx.waitForEvent(exports.EVENT_KEY, 'true');
158
+ const childResult = yield exports.spawnChildTask.run({});
159
+ return {
160
+ runtime: (Date.now() - start) / 1000,
161
+ child_output: childResult,
162
+ };
163
+ }),
164
+ });
165
+ // --- Spawn child using explicit ctx.spawnChild ---
166
+ exports.durableWithExplicitSpawn = hatchet_client_1.hatchet.durableTask({
167
+ name: 'durable-with-explicit-spawn',
168
+ executionTimeout: '10m',
169
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
170
+ const childResult = yield ctx.spawnChild(exports.spawnChildTask, {});
171
+ return { child_output: childResult };
172
+ }),
173
+ });
174
+ // --- Non-determinism detection ---
175
+ exports.durableNonDeterminism = hatchet_client_1.hatchet.durableTask({
176
+ name: 'durable-non-determinism',
177
+ executionTimeout: '10s',
178
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
179
+ const sleepTime = ctx.invocationCount * 2;
180
+ try {
181
+ yield ctx.sleepFor(`${sleepTime}s`);
182
+ }
183
+ catch (e) {
184
+ if (e instanceof non_determinism_error_1.NonDeterminismError) {
185
+ return {
186
+ attempt_number: ctx.invocationCount,
187
+ sleep_time: sleepTime,
188
+ non_determinism_detected: true,
189
+ node_id: e.nodeId,
190
+ };
191
+ }
192
+ throw e;
193
+ }
194
+ return {
195
+ attempt_number: ctx.invocationCount,
196
+ sleep_time: sleepTime,
197
+ non_determinism_detected: false,
198
+ };
199
+ }),
200
+ });
201
+ // --- Replay reset ---
202
+ exports.REPLAY_RESET_SLEEP_SECONDS = 3;
203
+ /** Max duration (seconds) for a replayed/memoized step; above this we treat it as a real sleep. */
204
+ exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = 5;
205
+ const REPLAY_RESET_SLEEP = `${exports.REPLAY_RESET_SLEEP_SECONDS}s`;
206
+ exports.durableReplayReset = hatchet_client_1.hatchet.durableTask({
207
+ name: 'durable-replay-reset',
208
+ executionTimeout: '20s',
209
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
210
+ let start = Date.now();
211
+ yield ctx.sleepFor(REPLAY_RESET_SLEEP);
212
+ const sleep1Duration = (Date.now() - start) / 1000;
213
+ start = Date.now();
214
+ yield ctx.sleepFor(REPLAY_RESET_SLEEP);
215
+ const sleep2Duration = (Date.now() - start) / 1000;
216
+ start = Date.now();
217
+ yield ctx.sleepFor(REPLAY_RESET_SLEEP);
218
+ const sleep3Duration = (Date.now() - start) / 1000;
219
+ return {
220
+ sleep_1_duration: sleep1Duration,
221
+ sleep_2_duration: sleep2Duration,
222
+ sleep_3_duration: sleep3Duration,
223
+ };
224
+ }),
225
+ });
226
+ exports.memoNowCaching = hatchet_client_1.hatchet.durableTask({
227
+ name: 'memo-now-caching',
228
+ executionTimeout: '10m',
229
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
230
+ const now = yield ctx.now();
231
+ return { start_time: now.toISOString() };
232
+ }),
233
+ });
234
+ // --- Spawn DAG from durable task ---
235
+ exports.dagChildWorkflow = hatchet_client_1.hatchet.workflow({
236
+ name: 'dag-child-workflow-ts',
237
+ });
238
+ const dagChild1 = exports.dagChildWorkflow.task({
239
+ name: 'dag-child-1',
240
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
241
+ yield (0, sleep_1.default)(1000);
242
+ return { result: 'child1' };
243
+ }),
244
+ });
245
+ exports.dagChildWorkflow.task({
246
+ name: 'dag-child-2',
247
+ parents: [dagChild1],
248
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
249
+ yield (0, sleep_1.default)(2000);
250
+ return { result: 'child2' };
251
+ }),
252
+ });
253
+ exports.durableSpawnDag = hatchet_client_1.hatchet.durableTask({
254
+ name: 'durable-spawn-dag',
255
+ executionTimeout: '10s',
256
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
257
+ const sleepStart = Date.now();
258
+ const sleepResult = yield ctx.sleepFor(exports.SLEEP_TIME);
259
+ const sleepDuration = (Date.now() - sleepStart) / 1000;
260
+ const spawnStart = Date.now();
261
+ const spawnResult = yield exports.dagChildWorkflow.run({});
262
+ const spawnDuration = (Date.now() - spawnStart) / 1000;
263
+ return {
264
+ sleep_duration: sleepDuration,
265
+ sleep_duration_ms: sleepResult.durationMs,
266
+ spawn_duration: spawnDuration,
267
+ spawn_result: spawnResult,
268
+ };
269
+ }),
270
+ });
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -15,7 +15,6 @@ function main() {
15
15
  const timeStart = Date.now();
16
16
  const res = yield workflow_1.durableEvent.run({});
17
17
  const timeEnd = Date.now();
18
- // eslint-disable-next-line no-console
19
18
  console.log(`Time taken: ${timeEnd - timeStart}ms`);
20
19
  });
21
20
  }
@@ -23,7 +22,6 @@ if (require.main === module) {
23
22
  main()
24
23
  .then(() => process.exit(0))
25
24
  .catch((error) => {
26
- // eslint-disable-next-line no-console
27
25
  console.error('Error:', error);
28
26
  process.exit(1);
29
27
  });
@@ -17,9 +17,7 @@ exports.durableEvent = hatchet_client_1.hatchet.durableTask({
17
17
  name: 'durable-event',
18
18
  executionTimeout: '10m',
19
19
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
20
- const res = ctx.waitFor({
21
- eventKey: 'user:update',
22
- });
20
+ const res = yield ctx.waitForEvent('user:update');
23
21
  console.log('res', res);
24
22
  return {
25
23
  Value: 'done',
@@ -32,10 +30,7 @@ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
32
30
  executionTimeout: '10m',
33
31
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
32
  // > Durable Event With Filter
35
- const res = ctx.waitFor({
36
- eventKey: 'user:update',
37
- expression: "input.userId == '1234'",
38
- });
33
+ const res = yield ctx.waitForEvent('user:update', "input.userId == '1234'");
39
34
  // !!
40
35
  console.log('res', res);
41
36
  return {
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -15,7 +15,6 @@ function main() {
15
15
  const timeStart = Date.now();
16
16
  const res = yield workflow_1.durableSleep.run({});
17
17
  const timeEnd = Date.now();
18
- // eslint-disable-next-line no-console
19
18
  console.log(`Time taken: ${timeEnd - timeStart}ms`);
20
19
  });
21
20
  }
@@ -23,7 +22,6 @@ if (require.main === module) {
23
22
  main()
24
23
  .then(() => process.exit(0))
25
24
  .catch((error) => {
26
- // eslint-disable-next-line no-console
27
25
  console.error('Error:', error);
28
26
  process.exit(1);
29
27
  });
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -15,7 +15,6 @@ function main() {
15
15
  const timeStart = Date.now();
16
16
  const res = yield workflow_1.durableEvent.run({});
17
17
  const timeEnd = Date.now();
18
- // eslint-disable-next-line no-console
19
18
  console.log(`Time taken: ${timeEnd - timeStart}ms`);
20
19
  });
21
20
  }
@@ -23,7 +22,6 @@ if (require.main === module) {
23
22
  main()
24
23
  .then(() => process.exit(0))
25
24
  .catch((error) => {
26
- // eslint-disable-next-line no-console
27
25
  console.error('Error:', error);
28
26
  process.exit(1);
29
27
  });
@@ -1,3 +1,4 @@
1
+ export declare const EVENT_KEY = "user:update";
1
2
  export declare const durableEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
2
3
  Value: string;
3
4
  }, {}, {}, {}, {}>;
@@ -9,17 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.durableEventWithFilter = exports.durableEvent = void 0;
13
- // import sleep from '../../../util/sleep.js';
12
+ exports.durableEventWithFilter = exports.durableEvent = exports.EVENT_KEY = void 0;
14
13
  const hatchet_client_1 = require("../hatchet-client");
14
+ exports.EVENT_KEY = 'user:update';
15
15
  // > Durable Event
16
16
  exports.durableEvent = hatchet_client_1.hatchet.durableTask({
17
17
  name: 'durable-event',
18
18
  executionTimeout: '10m',
19
19
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
20
- const res = ctx.waitFor({
21
- eventKey: 'user:update',
22
- });
20
+ const res = yield ctx.waitForEvent(exports.EVENT_KEY);
23
21
  console.log('res', res);
24
22
  return {
25
23
  Value: 'done',
@@ -32,10 +30,7 @@ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
32
30
  executionTimeout: '10m',
33
31
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
32
  // > Durable Event With Filter
35
- const res = ctx.waitFor({
36
- eventKey: 'user:update',
37
- expression: "input.userId == '1234'",
38
- });
33
+ const res = yield ctx.waitForEvent(exports.EVENT_KEY, "input.userId == '1234'");
39
34
  // !!
40
35
  console.log('res', res);
41
36
  return {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /**
13
+ * Dedicated worker for capacity-eviction e2e tests.
14
+ *
15
+ * Runs with durableSlots=1 so that a single waiting durable task triggers
16
+ * capacity pressure and gets evicted (even with ttl=undefined).
17
+ */
18
+ const hatchet_client_1 = require("../hatchet-client");
19
+ const workflow_1 = require("./workflow");
20
+ function main() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const worker = yield hatchet_client_1.hatchet.worker('capacity-eviction-worker', {
23
+ durableSlots: 1,
24
+ workflows: [workflow_1.capacityEvictableSleep],
25
+ });
26
+ yield worker.start();
27
+ });
28
+ }
29
+ if (require.main === module) {
30
+ main();
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('eviction-worker', {
17
+ workflows: [
18
+ workflow_1.evictableSleep,
19
+ workflow_1.evictableWaitForEvent,
20
+ workflow_1.evictableChildSpawn,
21
+ workflow_1.evictableChildBulkSpawn,
22
+ workflow_1.multipleEviction,
23
+ workflow_1.nonEvictableSleep,
24
+ workflow_1.childTask,
25
+ workflow_1.bulkChildTask,
26
+ workflow_1.evictableSleepForGracefulTermination,
27
+ ],
28
+ });
29
+ yield worker.start();
30
+ });
31
+ }
32
+ if (require.main === module) {
33
+ main();
34
+ }
@@ -0,0 +1,44 @@
1
+ export declare const EVICTION_TTL_SECONDS = 5;
2
+ export declare const LONG_SLEEP_SECONDS = 15;
3
+ export declare const EVENT_KEY = "durable-eviction:event";
4
+ export declare const childTask: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
5
+ child_status: string;
6
+ }, {}, {}, {}, {}>;
7
+ export declare const evictableSleep: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
8
+ status: string;
9
+ }, {}, {}, {}, {}>;
10
+ export declare const evictableSleepForGracefulTermination: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
11
+ status: string;
12
+ }, {}, {}, {}, {}>;
13
+ export declare const evictableWaitForEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
14
+ status: string;
15
+ }, {}, {}, {}, {}>;
16
+ export declare const evictableChildSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
17
+ child: {
18
+ child_status: string;
19
+ };
20
+ status: string;
21
+ }, {}, {}, {}, {}>;
22
+ export declare const multipleEviction: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
23
+ status: string;
24
+ }, {}, {}, {}, {}>;
25
+ export declare const bulkChildTask: import("../..").TaskWorkflowDeclaration<{
26
+ sleepSeconds: number;
27
+ }, {
28
+ sleepSeconds: number;
29
+ status: string;
30
+ }, {}, {}, {}, {}>;
31
+ export declare const evictableChildBulkSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
32
+ child_results: {
33
+ sleepSeconds: number;
34
+ status: string;
35
+ }[];
36
+ status: string;
37
+ }, {}, {}, {}, {}>;
38
+ export declare const CAPACITY_SLEEP_SECONDS = 20;
39
+ export declare const capacityEvictableSleep: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
40
+ status: string;
41
+ }, {}, {}, {}, {}>;
42
+ export declare const nonEvictableSleep: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
43
+ status: string;
44
+ }, {}, {}, {}, {}>;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.nonEvictableSleep = exports.capacityEvictableSleep = exports.CAPACITY_SLEEP_SECONDS = exports.evictableChildBulkSpawn = exports.bulkChildTask = exports.multipleEviction = exports.evictableChildSpawn = exports.evictableWaitForEvent = exports.evictableSleepForGracefulTermination = exports.evictableSleep = exports.childTask = exports.EVENT_KEY = exports.LONG_SLEEP_SECONDS = exports.EVICTION_TTL_SECONDS = void 0;
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const hatchet_client_1 = require("../hatchet-client");
18
+ exports.EVICTION_TTL_SECONDS = 5;
19
+ exports.LONG_SLEEP_SECONDS = 15;
20
+ exports.EVENT_KEY = 'durable-eviction:event';
21
+ const EVICTION_POLICY = {
22
+ ttl: `${exports.EVICTION_TTL_SECONDS}s`,
23
+ allowCapacityEviction: true,
24
+ priority: 0,
25
+ };
26
+ exports.childTask = hatchet_client_1.hatchet.task({
27
+ name: 'eviction-child-task',
28
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
29
+ yield (0, sleep_1.default)(exports.LONG_SLEEP_SECONDS * 1000);
30
+ return { child_status: 'completed' };
31
+ }),
32
+ });
33
+ exports.evictableSleep = hatchet_client_1.hatchet.durableTask({
34
+ name: 'evictable-sleep',
35
+ executionTimeout: '5m',
36
+ evictionPolicy: EVICTION_POLICY,
37
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
38
+ yield ctx.sleepFor(`${exports.LONG_SLEEP_SECONDS}s`);
39
+ return { status: 'completed' };
40
+ }),
41
+ });
42
+ // NOTE: DO NOT REGISTER ON E2E TEST WORKER
43
+ exports.evictableSleepForGracefulTermination = hatchet_client_1.hatchet.durableTask({
44
+ name: 'evictable-sleep-for-graceful-termination',
45
+ executionTimeout: '5m',
46
+ evictionPolicy: {
47
+ ttl: `30m`,
48
+ allowCapacityEviction: true,
49
+ priority: 0,
50
+ },
51
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
52
+ yield ctx.sleepFor(`5m`);
53
+ return { status: 'completed' };
54
+ }),
55
+ });
56
+ exports.evictableWaitForEvent = hatchet_client_1.hatchet.durableTask({
57
+ name: 'evictable-wait-for-event',
58
+ executionTimeout: '5m',
59
+ evictionPolicy: EVICTION_POLICY,
60
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
61
+ yield ctx.waitForEvent(exports.EVENT_KEY, 'true');
62
+ return { status: 'completed' };
63
+ }),
64
+ });
65
+ exports.evictableChildSpawn = hatchet_client_1.hatchet.durableTask({
66
+ name: 'evictable-child-spawn',
67
+ executionTimeout: '5m',
68
+ evictionPolicy: EVICTION_POLICY,
69
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
70
+ const childResult = yield exports.childTask.run({});
71
+ return { child: childResult, status: 'completed' };
72
+ }),
73
+ });
74
+ exports.multipleEviction = hatchet_client_1.hatchet.durableTask({
75
+ name: 'multiple-eviction',
76
+ executionTimeout: '5m',
77
+ evictionPolicy: EVICTION_POLICY,
78
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
79
+ yield ctx.sleepFor(`${exports.LONG_SLEEP_SECONDS}s`);
80
+ yield ctx.sleepFor(`${exports.LONG_SLEEP_SECONDS}s`);
81
+ return { status: 'completed' };
82
+ }),
83
+ });
84
+ exports.bulkChildTask = hatchet_client_1.hatchet.task({
85
+ name: 'eviction-bulk-child-task',
86
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
87
+ yield (0, sleep_1.default)(input.sleepSeconds * 1000);
88
+ return { sleepSeconds: input.sleepSeconds, status: 'completed' };
89
+ }),
90
+ });
91
+ exports.evictableChildBulkSpawn = hatchet_client_1.hatchet.durableTask({
92
+ name: 'evictable-child-bulk-spawn',
93
+ executionTimeout: '5m',
94
+ evictionPolicy: EVICTION_POLICY,
95
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
96
+ const inputs = Array.from({ length: 3 }, (_, i) => ({
97
+ sleepSeconds: (exports.EVICTION_TTL_SECONDS + 5) * (i + 1),
98
+ }));
99
+ const childResults = yield exports.bulkChildTask.run(inputs);
100
+ return { child_results: childResults, status: 'completed' };
101
+ }),
102
+ });
103
+ exports.CAPACITY_SLEEP_SECONDS = 20;
104
+ exports.capacityEvictableSleep = hatchet_client_1.hatchet.durableTask({
105
+ name: 'capacity-evictable-sleep',
106
+ executionTimeout: '5m',
107
+ evictionPolicy: {
108
+ ttl: undefined,
109
+ allowCapacityEviction: true,
110
+ priority: 0,
111
+ },
112
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
113
+ yield ctx.sleepFor(`${exports.CAPACITY_SLEEP_SECONDS}s`);
114
+ return { status: 'completed' };
115
+ }),
116
+ });
117
+ exports.nonEvictableSleep = hatchet_client_1.hatchet.durableTask({
118
+ name: 'non-evictable-sleep',
119
+ executionTimeout: '5m',
120
+ evictionPolicy: {
121
+ ttl: undefined,
122
+ allowCapacityEviction: false,
123
+ priority: 0,
124
+ },
125
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
126
+ yield ctx.sleepFor('10s');
127
+ return { status: 'completed' };
128
+ }),
129
+ });
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -15,7 +15,6 @@ function main() {
15
15
  const timeStart = Date.now();
16
16
  const res = yield workflow_1.durableSleep.run({});
17
17
  const timeEnd = Date.now();
18
- // eslint-disable-next-line no-console
19
18
  console.log(`Time taken: ${timeEnd - timeStart}ms`);
20
19
  });
21
20
  }
@@ -23,7 +22,6 @@ if (require.main === module) {
23
22
  main()
24
23
  .then(() => process.exit(0))
25
24
  .catch((error) => {
26
- // eslint-disable-next-line no-console
27
25
  console.error('Error:', error);
28
26
  process.exit(1);
29
27
  });