@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.0.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 (194) hide show
  1. package/clients/admin/admin-client.d.ts +15 -20
  2. package/clients/admin/admin-client.js +21 -17
  3. package/clients/hatchet-client/hatchet-client.d.ts +5 -4
  4. package/clients/hatchet-client/hatchet-client.js +6 -4
  5. package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
  6. package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
  7. package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
  8. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
  9. package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
  10. package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
  11. package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
  12. package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
  13. package/clients/rest/generated/Api.d.ts +49 -2
  14. package/clients/rest/generated/Api.js +30 -0
  15. package/clients/rest/generated/data-contracts.d.ts +88 -82
  16. package/clients/rest/generated/data-contracts.js +8 -1
  17. package/clients/worker/worker.d.ts +5 -1
  18. package/clients/worker/worker.js +173 -2
  19. package/examples/affinity-workers.js +5 -1
  20. package/examples/api.js +1 -1
  21. package/examples/bulk-fanout-worker.js +1 -1
  22. package/examples/byo-logger.js +4 -0
  23. package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
  24. package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
  25. package/examples/crons/programatic-crons.js +4 -4
  26. package/examples/dag-worker.js +0 -1
  27. package/examples/example-event.js +2 -2
  28. package/examples/logger.js +2 -0
  29. package/examples/on-failure.js +1 -1
  30. package/examples/rate-limit/events.js +3 -3
  31. package/examples/scheduled-runs/programatic-schedules.js +4 -4
  32. package/examples/sticky-worker-with-check.js +2 -2
  33. package/examples/sticky-worker.js +5 -0
  34. package/index.d.ts +1 -3
  35. package/index.js +1 -3
  36. package/package.json +2 -2
  37. package/protoc/dispatcher/dispatcher.d.ts +2 -0
  38. package/protoc/dispatcher/dispatcher.js +1 -1
  39. package/protoc/events/events.js +1 -1
  40. package/protoc/google/protobuf/timestamp.js +1 -1
  41. package/protoc/v1/dispatcher.d.ts +77 -0
  42. package/protoc/v1/dispatcher.js +341 -0
  43. package/protoc/v1/shared/condition.d.ts +59 -0
  44. package/protoc/v1/shared/condition.js +549 -0
  45. package/protoc/v1/workflows.d.ts +263 -0
  46. package/protoc/v1/workflows.js +1823 -0
  47. package/protoc/workflows/workflows.js +1 -1
  48. package/step.d.ts +173 -47
  49. package/step.js +208 -64
  50. package/util/sleep.d.ts +7 -0
  51. package/util/sleep.js +7 -0
  52. package/util/workflow-run-ref.d.ts +8 -2
  53. package/util/workflow-run-ref.js +13 -0
  54. package/v1/client/client.d.ts +125 -7
  55. package/v1/client/client.interface.d.ts +9 -1
  56. package/v1/client/client.js +148 -17
  57. package/v1/client/duration.d.ts +7 -0
  58. package/v1/client/duration.js +2 -0
  59. package/v1/client/features/index.d.ts +5 -0
  60. package/v1/client/features/index.js +21 -0
  61. package/v1/client/features/metrics.d.ts +14 -0
  62. package/v1/client/features/metrics.js +45 -0
  63. package/v1/client/features/ratelimits.d.ts +20 -0
  64. package/v1/client/features/ratelimits.js +40 -0
  65. package/v1/client/features/runs.d.ts +15 -0
  66. package/v1/client/features/runs.js +60 -0
  67. package/v1/client/features/workers.d.ts +14 -0
  68. package/v1/client/features/workers.js +56 -0
  69. package/v1/client/features/workflows.d.ts +17 -0
  70. package/v1/client/features/workflows.js +93 -0
  71. package/v1/client/worker.d.ts +25 -15
  72. package/v1/client/worker.js +76 -47
  73. package/v1/conditions/base.d.ts +18 -0
  74. package/v1/conditions/base.js +18 -0
  75. package/v1/conditions/index.d.ts +31 -0
  76. package/v1/conditions/index.js +91 -0
  77. package/v1/conditions/parent-condition.d.ts +40 -0
  78. package/v1/conditions/parent-condition.js +36 -0
  79. package/v1/conditions/sleep-condition.d.ts +47 -0
  80. package/v1/conditions/sleep-condition.js +38 -0
  81. package/v1/conditions/transformer.d.ts +5 -0
  82. package/v1/conditions/transformer.js +52 -0
  83. package/v1/conditions/user-event-condition.d.ts +50 -0
  84. package/v1/conditions/user-event-condition.js +39 -0
  85. package/v1/declaration.d.ts +309 -0
  86. package/v1/declaration.js +296 -0
  87. package/v1/examples/child_workflows/worker.js +2 -2
  88. package/v1/examples/child_workflows/workflow.d.ts +2 -2
  89. package/v1/examples/child_workflows/workflow.js +5 -3
  90. package/v1/examples/concurrency-rr/load.js +2 -2
  91. package/v1/examples/concurrency-rr/worker.js +2 -2
  92. package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
  93. package/v1/examples/concurrency-rr/workflow.js +2 -3
  94. package/v1/examples/dag/worker.js +2 -2
  95. package/v1/examples/dag/workflow.d.ts +1 -1
  96. package/v1/examples/dag/workflow.js +3 -3
  97. package/v1/examples/dag_match_condition/event.js +28 -0
  98. package/v1/examples/dag_match_condition/run.d.ts +1 -0
  99. package/v1/examples/dag_match_condition/run.js +25 -0
  100. package/v1/examples/dag_match_condition/worker.d.ts +1 -0
  101. package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
  102. package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
  103. package/v1/examples/dag_match_condition/workflow.js +41 -0
  104. package/v1/examples/deep/worker.js +2 -2
  105. package/v1/examples/deep/workflow.d.ts +6 -6
  106. package/v1/examples/deep/workflow.js +7 -7
  107. package/v1/examples/durable-sleep/event.d.ts +1 -0
  108. package/v1/examples/durable-sleep/event.js +28 -0
  109. package/v1/examples/durable-sleep/run.d.ts +1 -0
  110. package/v1/examples/durable-sleep/run.js +30 -0
  111. package/v1/examples/durable-sleep/worker.d.ts +1 -0
  112. package/v1/examples/durable-sleep/worker.js +24 -0
  113. package/v1/examples/durable-sleep/workflow.d.ts +1 -0
  114. package/v1/examples/durable-sleep/workflow.js +37 -0
  115. package/v1/examples/inferred-typing/run.d.ts +1 -0
  116. package/v1/examples/inferred-typing/run.js +41 -0
  117. package/v1/examples/inferred-typing/worker.d.ts +1 -0
  118. package/v1/examples/inferred-typing/worker.js +24 -0
  119. package/v1/examples/inferred-typing/workflow.d.ts +15 -0
  120. package/v1/examples/inferred-typing/workflow.js +44 -0
  121. package/v1/examples/landing_page/durable-excution.d.ts +3 -0
  122. package/v1/examples/landing_page/durable-excution.js +40 -0
  123. package/v1/examples/landing_page/event-signaling.d.ts +6 -0
  124. package/v1/examples/landing_page/event-signaling.js +16 -0
  125. package/v1/examples/landing_page/flow-control.d.ts +6 -0
  126. package/v1/examples/landing_page/flow-control.js +26 -0
  127. package/v1/examples/landing_page/queues.d.ts +3 -0
  128. package/v1/examples/landing_page/queues.js +33 -0
  129. package/v1/examples/landing_page/scheduling.d.ts +1 -0
  130. package/v1/examples/landing_page/scheduling.js +12 -0
  131. package/v1/examples/landing_page/task-routing.d.ts +6 -0
  132. package/v1/examples/landing_page/task-routing.js +25 -0
  133. package/v1/examples/legacy/run.js +2 -2
  134. package/v1/examples/legacy/worker.js +2 -2
  135. package/v1/examples/on_cron/worker.d.ts +1 -0
  136. package/v1/examples/on_cron/worker.js +24 -0
  137. package/v1/examples/on_cron/workflow.d.ts +10 -0
  138. package/v1/examples/on_cron/workflow.js +21 -0
  139. package/v1/examples/on_event/event.js +3 -2
  140. package/v1/examples/on_event/worker.js +2 -2
  141. package/v1/examples/on_event/workflow.d.ts +4 -4
  142. package/v1/examples/on_event/workflow.js +6 -3
  143. package/v1/examples/on_event copy/event.d.ts +1 -0
  144. package/v1/examples/on_event copy/event.js +26 -0
  145. package/v1/examples/on_event copy/worker.d.ts +1 -0
  146. package/v1/examples/on_event copy/worker.js +24 -0
  147. package/v1/examples/on_event copy/workflow.d.ts +16 -0
  148. package/v1/examples/on_event copy/workflow.js +35 -0
  149. package/v1/examples/on_failure/worker.js +2 -2
  150. package/v1/examples/on_failure/workflow.d.ts +1 -1
  151. package/v1/examples/on_failure/workflow.js +18 -8
  152. package/v1/examples/on_success/run.d.ts +1 -0
  153. package/v1/examples/on_success/run.js +31 -0
  154. package/v1/examples/on_success/worker.d.ts +1 -0
  155. package/v1/examples/on_success/worker.js +24 -0
  156. package/v1/examples/on_success/workflow.d.ts +4 -0
  157. package/v1/examples/on_success/workflow.js +59 -0
  158. package/v1/examples/retries/run.d.ts +1 -0
  159. package/v1/examples/retries/run.js +29 -0
  160. package/v1/examples/retries/worker.d.ts +1 -0
  161. package/v1/examples/retries/worker.js +24 -0
  162. package/v1/examples/retries/workflow.d.ts +5 -0
  163. package/v1/examples/retries/workflow.js +53 -0
  164. package/v1/examples/simple/client-run.d.ts +1 -0
  165. package/v1/examples/simple/client-run.js +16 -0
  166. package/v1/examples/simple/cron.js +6 -2
  167. package/v1/examples/simple/delay.js +2 -2
  168. package/v1/examples/simple/enqueue.d.ts +1 -0
  169. package/v1/examples/simple/enqueue.js +43 -0
  170. package/v1/examples/simple/run.js +8 -3
  171. package/v1/examples/simple/schedule.js +11 -5
  172. package/v1/examples/simple/stub-workflow.d.ts +9 -0
  173. package/v1/examples/simple/stub-workflow.js +17 -0
  174. package/v1/examples/simple/worker.js +7 -2
  175. package/v1/examples/simple/workflow.d.ts +4 -3
  176. package/v1/examples/simple/workflow.js +5 -5
  177. package/v1/examples/sticky/run.d.ts +1 -0
  178. package/v1/examples/sticky/run.js +29 -0
  179. package/v1/examples/sticky/worker.d.ts +1 -0
  180. package/v1/examples/sticky/worker.js +24 -0
  181. package/v1/examples/sticky/workflow.d.ts +7 -0
  182. package/v1/examples/sticky/workflow.js +32 -0
  183. package/v1/examples/with_timeouts/workflow.d.ts +9 -0
  184. package/v1/examples/with_timeouts/workflow.js +62 -0
  185. package/v1/index.d.ts +5 -0
  186. package/v1/index.js +20 -0
  187. package/v1/task.d.ts +144 -14
  188. package/version.d.ts +1 -1
  189. package/version.js +1 -1
  190. package/v1/workflow.d.ts +0 -158
  191. package/v1/workflow.js +0 -145
  192. /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
  193. /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
  194. /package/v1/examples/{client.js → hatchet-client.js} +0 -0
@@ -25,6 +25,7 @@ const dispatcher_1 = require("../../protoc/dispatcher");
25
25
  const hatchet_promise_1 = __importDefault(require("../../util/hatchet-promise/hatchet-promise"));
26
26
  const workflows_1 = require("../../protoc/workflows");
27
27
  const handler_1 = require("./handler");
28
+ const transformer_1 = require("../../v1/conditions/transformer");
28
29
  const step_1 = require("../../step");
29
30
  class V0Worker {
30
31
  constructor(client, options) {
@@ -61,6 +62,7 @@ class V0Worker {
61
62
  ? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name.toLowerCase()}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
62
63
  }
63
64
  getHandler(workflows) {
65
+ // TODO v1
64
66
  for (const workflow of workflows) {
65
67
  const wf = Object.assign(Object.assign({}, workflow), { id: this.client.config.namespace + workflow.id });
66
68
  this.registerActions(wf);
@@ -80,6 +82,163 @@ class V0Worker {
80
82
  return this.registerWorkflow(initWorkflow);
81
83
  });
82
84
  }
85
+ registerDurableActionsV1(workflow) {
86
+ const newActions = workflow._durableTasks.reduce((acc, task) => {
87
+ acc[`${workflow.name}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.workflowInput(), ctx);
88
+ return acc;
89
+ }, {});
90
+ this.action_registry = Object.assign(Object.assign({}, this.action_registry), newActions);
91
+ }
92
+ registerActionsV1(workflow) {
93
+ const newActions = workflow._tasks.reduce((acc, task) => {
94
+ acc[`${workflow.name}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.workflowInput(), ctx);
95
+ return acc;
96
+ }, {});
97
+ const onFailureFn = workflow.onFailure
98
+ ? typeof workflow.onFailure === 'function'
99
+ ? workflow.onFailure
100
+ : workflow.onFailure.fn
101
+ : undefined;
102
+ const onFailureAction = onFailureFn
103
+ ? {
104
+ [onFailureTaskName(workflow)]: (ctx) => onFailureFn(ctx.workflowInput(), ctx),
105
+ }
106
+ : {};
107
+ this.action_registry = Object.assign(Object.assign(Object.assign({}, this.action_registry), newActions), onFailureAction);
108
+ }
109
+ registerWorkflowV1(initWorkflow) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
112
+ // patch the namespace
113
+ const workflow = Object.assign(Object.assign({}, initWorkflow.definition), { name: (this.client.config.namespace + initWorkflow.definition.name).toLowerCase() });
114
+ try {
115
+ const { concurrency } = workflow;
116
+ let onFailureTask;
117
+ if (workflow.onFailure && typeof workflow.onFailure === 'function') {
118
+ onFailureTask = {
119
+ readableId: 'on-failure-task',
120
+ action: onFailureTaskName(workflow),
121
+ timeout: '60s',
122
+ inputs: '{}',
123
+ parents: [],
124
+ retries: 0,
125
+ rateLimits: [],
126
+ workerLabels: {},
127
+ concurrency: [],
128
+ };
129
+ }
130
+ if (workflow.onFailure && typeof workflow.onFailure === 'object') {
131
+ const onFailure = workflow.onFailure;
132
+ onFailureTask = {
133
+ readableId: 'on-failure-task',
134
+ action: onFailureTaskName(workflow),
135
+ timeout: onFailure.executionTimeout || ((_a = workflow.taskDefaults) === null || _a === void 0 ? void 0 : _a.executionTimeout) || '60s',
136
+ scheduleTimeout: onFailure.scheduleTimeout || ((_b = workflow.taskDefaults) === null || _b === void 0 ? void 0 : _b.scheduleTimeout),
137
+ inputs: '{}',
138
+ parents: [],
139
+ retries: onFailure.retries || ((_c = workflow.taskDefaults) === null || _c === void 0 ? void 0 : _c.retries) || 0,
140
+ rateLimits: (0, step_1.mapRateLimit)(onFailure.rateLimits || ((_d = workflow.taskDefaults) === null || _d === void 0 ? void 0 : _d.rateLimits)),
141
+ workerLabels: toPbWorkerLabel(onFailure.desiredWorkerLabels || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.workerLabels)),
142
+ concurrency: [],
143
+ backoffFactor: ((_f = onFailure.backoff) === null || _f === void 0 ? void 0 : _f.factor) || ((_h = (_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.backoff) === null || _h === void 0 ? void 0 : _h.factor),
144
+ backoffMaxSeconds: ((_j = onFailure.backoff) === null || _j === void 0 ? void 0 : _j.maxSeconds) || ((_l = (_k = workflow.taskDefaults) === null || _k === void 0 ? void 0 : _k.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds),
145
+ };
146
+ }
147
+ let onSuccessTask;
148
+ if (workflow.onSuccess && typeof workflow.onSuccess === 'function') {
149
+ const parents = getLeaves(workflow._tasks);
150
+ onSuccessTask = {
151
+ name: 'on-success-task',
152
+ fn: workflow.onSuccess,
153
+ timeout: '60s',
154
+ parents,
155
+ retries: 0,
156
+ rateLimits: [],
157
+ desiredWorkerLabels: {},
158
+ concurrency: [],
159
+ };
160
+ }
161
+ if (workflow.onSuccess && typeof workflow.onSuccess === 'object') {
162
+ const onSuccess = workflow.onSuccess;
163
+ const parents = getLeaves(workflow._tasks);
164
+ onSuccessTask = {
165
+ name: 'on-success-task',
166
+ fn: onSuccess.fn,
167
+ timeout: onSuccess.executionTimeout || ((_m = workflow.taskDefaults) === null || _m === void 0 ? void 0 : _m.executionTimeout) || '60s',
168
+ scheduleTimeout: onSuccess.scheduleTimeout || ((_o = workflow.taskDefaults) === null || _o === void 0 ? void 0 : _o.scheduleTimeout),
169
+ parents,
170
+ retries: onSuccess.retries || ((_p = workflow.taskDefaults) === null || _p === void 0 ? void 0 : _p.retries) || 0,
171
+ rateLimits: onSuccess.rateLimits || ((_q = workflow.taskDefaults) === null || _q === void 0 ? void 0 : _q.rateLimits),
172
+ desiredWorkerLabels: onSuccess.desiredWorkerLabels || ((_r = workflow.taskDefaults) === null || _r === void 0 ? void 0 : _r.workerLabels),
173
+ concurrency: onSuccess.concurrency || ((_s = workflow.taskDefaults) === null || _s === void 0 ? void 0 : _s.concurrency),
174
+ backoff: onSuccess.backoff || ((_t = workflow.taskDefaults) === null || _t === void 0 ? void 0 : _t.backoff),
175
+ };
176
+ }
177
+ if (onSuccessTask) {
178
+ workflow._tasks.push(onSuccessTask);
179
+ }
180
+ // cron and event triggers
181
+ if (workflow.on) {
182
+ this.logger.warn(`\`on\` for event and cron triggers is deprecated and will be removed soon, use \`onEvents\` and \`onCrons\` instead for ${workflow.name}`);
183
+ }
184
+ const eventTriggers = [
185
+ ...(workflow.onEvents || []),
186
+ ...(((_u = workflow.on) === null || _u === void 0 ? void 0 : _u.event) ? [workflow.on.event] : []),
187
+ ];
188
+ const cronTriggers = [
189
+ ...(workflow.onCrons || []),
190
+ ...(((_v = workflow.on) === null || _v === void 0 ? void 0 : _v.cron) ? [workflow.on.cron] : []),
191
+ ];
192
+ const registeredWorkflow = this.client.admin.putWorkflowV1({
193
+ name: workflow.name,
194
+ description: workflow.description || '',
195
+ version: workflow.version || '',
196
+ eventTriggers,
197
+ cronTriggers,
198
+ sticky: workflow.sticky,
199
+ concurrency,
200
+ onFailureTask,
201
+ tasks: [...workflow._tasks, ...workflow._durableTasks].map((task) => {
202
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
203
+ return ({
204
+ readableId: task.name,
205
+ action: `${workflow.name}:${task.name}`,
206
+ timeout: task.executionTimeout ||
207
+ task.timeout ||
208
+ ((_a = workflow.taskDefaults) === null || _a === void 0 ? void 0 : _a.executionTimeout) ||
209
+ '60s',
210
+ scheduleTimeout: task.scheduleTimeout || ((_b = workflow.taskDefaults) === null || _b === void 0 ? void 0 : _b.scheduleTimeout),
211
+ inputs: '{}',
212
+ parents: (_d = (_c = task.parents) === null || _c === void 0 ? void 0 : _c.map((p) => p.name)) !== null && _d !== void 0 ? _d : [],
213
+ userData: '{}',
214
+ retries: task.retries || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.retries) || 0,
215
+ rateLimits: (0, step_1.mapRateLimit)(task.rateLimits || ((_f = workflow.taskDefaults) === null || _f === void 0 ? void 0 : _f.rateLimits)),
216
+ workerLabels: toPbWorkerLabel(task.desiredWorkerLabels || ((_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.workerLabels)),
217
+ backoffFactor: ((_h = task.backoff) === null || _h === void 0 ? void 0 : _h.factor) || ((_k = (_j = workflow.taskDefaults) === null || _j === void 0 ? void 0 : _j.backoff) === null || _k === void 0 ? void 0 : _k.factor),
218
+ backoffMaxSeconds: ((_l = task.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds) || ((_o = (_m = workflow.taskDefaults) === null || _m === void 0 ? void 0 : _m.backoff) === null || _o === void 0 ? void 0 : _o.maxSeconds),
219
+ conditions: (0, transformer_1.taskConditionsToPb)(task),
220
+ concurrency: task.concurrency
221
+ ? Array.isArray(task.concurrency)
222
+ ? task.concurrency
223
+ : [task.concurrency]
224
+ : ((_p = workflow.taskDefaults) === null || _p === void 0 ? void 0 : _p.concurrency)
225
+ ? Array.isArray(workflow.taskDefaults.concurrency)
226
+ ? workflow.taskDefaults.concurrency
227
+ : [workflow.taskDefaults.concurrency]
228
+ : [],
229
+ });
230
+ }),
231
+ });
232
+ this.registeredWorkflowPromises.push(registeredWorkflow);
233
+ yield registeredWorkflow;
234
+ this.workflow_registry.push(workflow);
235
+ }
236
+ catch (e) {
237
+ throw new hatchet_error_1.default(`Could not register workflow: ${e.message}`);
238
+ }
239
+ this.registerActionsV1(workflow);
240
+ });
241
+ }
83
242
  registerWorkflow(initWorkflow) {
84
243
  return __awaiter(this, void 0, void 0, function* () {
85
244
  var _a, _b, _c;
@@ -170,7 +329,8 @@ class V0Worker {
170
329
  return __awaiter(this, void 0, void 0, function* () {
171
330
  const { actionId } = action;
172
331
  try {
173
- const context = new step_1.Context(action, this.client, this);
332
+ // Note: we always use a DurableContext since its a superset of the Context class
333
+ const context = new step_1.DurableContext(action, this.client, this);
174
334
  this.contexts[action.stepRunId] = context;
175
335
  const step = this.action_registry[actionId];
176
336
  if (!step) {
@@ -412,6 +572,9 @@ class V0Worker {
412
572
  var _a, e_1, _b, _c;
413
573
  // ensure all workflows are registered
414
574
  yield Promise.all(this.registeredWorkflowPromises);
575
+ if (Object.keys(this.action_registry).length === 0) {
576
+ return;
577
+ }
415
578
  try {
416
579
  this.listener = yield this.client.dispatcher.getActionListener({
417
580
  workerName: this.name,
@@ -441,7 +604,6 @@ class V0Worker {
441
604
  }
442
605
  }
443
606
  catch (e) {
444
- // TODO TEMP this needs to be handled better
445
607
  if (this.killing) {
446
608
  this.logger.info(`Exiting worker, ignoring error: ${e.message}`);
447
609
  return;
@@ -515,3 +677,12 @@ function toPbWorkerLabel(in_) {
515
677
  } });
516
678
  }, {});
517
679
  }
680
+ function onFailureTaskName(workflow) {
681
+ return `${workflow.name}:on-failure-task`;
682
+ }
683
+ function getLeaves(tasks) {
684
+ return tasks.filter((task) => isLeafTask(task, tasks));
685
+ }
686
+ function isLeafTask(task, allTasks) {
687
+ return !allTasks.some((t) => { var _a; return (_a = t.parents) === null || _a === void 0 ? void 0 : _a.some((p) => p.name === task.name); });
688
+ }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const workflows_1 = require("../protoc/workflows");
16
16
  const sdk_1 = __importDefault(require("../sdk"));
17
17
  const hatchet = sdk_1.default.init();
18
+ // ❓ AffinityWorkflow
18
19
  const workflow = {
19
20
  id: 'affinity-workflow',
20
21
  description: 'test',
@@ -26,7 +27,7 @@ const workflow = {
26
27
  // eslint-disable-next-line no-plusplus
27
28
  for (let i = 0; i < 50; i++) {
28
29
  const result = yield ctx.spawnWorkflow(childWorkflow.id, {});
29
- results.push(result.result());
30
+ results.push(result.output);
30
31
  }
31
32
  console.log('Spawned 50 child workflows');
32
33
  console.log('Results:', yield Promise.all(results));
@@ -35,6 +36,7 @@ const workflow = {
35
36
  },
36
37
  ],
37
38
  };
39
+ // ‼️
38
40
  const childWorkflow = {
39
41
  id: 'child-affinity-workflow',
40
42
  description: 'test',
@@ -70,12 +72,14 @@ const childWorkflow = {
70
72
  };
71
73
  function main() {
72
74
  return __awaiter(this, void 0, void 0, function* () {
75
+ // ❓ AffinityWorker
73
76
  const worker1 = yield hatchet.worker('affinity-worker-1', {
74
77
  labels: {
75
78
  model: 'abc',
76
79
  memory: 1024,
77
80
  },
78
81
  });
82
+ // ‼️
79
83
  yield worker1.registerWorkflow(workflow);
80
84
  yield worker1.registerWorkflow(childWorkflow);
81
85
  worker1.start();
package/examples/api.js CHANGED
@@ -49,7 +49,7 @@ function main() {
49
49
  const { admin } = hatchet;
50
50
  yield admin.putWorkflow(opts);
51
51
  const worker = yield hatchet.worker('example-worker');
52
- worker.v0.registerAction('slack:example', (ctx) => __awaiter(this, void 0, void 0, function* () {
52
+ worker.nonDurable.registerAction('slack:example', (ctx) => __awaiter(this, void 0, void 0, function* () {
53
53
  const setData = ctx.userData();
54
54
  console.log('executed step1!', setData);
55
55
  return { step1: 'step1' };
@@ -32,7 +32,7 @@ const parentWorkflow = {
32
32
  options: { additionalMetadata: { childKey: 'childValue' } },
33
33
  }));
34
34
  const spawnedWorkflows = yield ctx.spawnWorkflows(workflowRequests);
35
- const results = yield Promise.all(spawnedWorkflows.map((workflowRef) => workflowRef.result().then((result) => {
35
+ const results = yield Promise.all(spawnedWorkflows.map((workflowRef) => workflowRef.output.then((result) => {
36
36
  ctx.log('spawned workflow result:');
37
37
  return result;
38
38
  })));
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  // eslint-disable-next-line import/no-extraneous-dependencies
16
16
  const pino_1 = __importDefault(require("pino"));
17
17
  const sdk_1 = __importDefault(require("../sdk"));
18
+ // ❓ Create Pino logger
18
19
  const logger = (0, pino_1.default)();
19
20
  class PinoLogger {
20
21
  constructor(context, logLevel = 'DEBUG') {
@@ -41,6 +42,8 @@ const hatchet = sdk_1.default.init({
41
42
  log_level: 'DEBUG',
42
43
  logger: (ctx, level) => new PinoLogger(ctx, level),
43
44
  });
45
+ // !!
46
+ // ❓ Use the logger
44
47
  const sleep = (ms) => new Promise((resolve) => {
45
48
  setTimeout(resolve, ms);
46
49
  });
@@ -64,6 +67,7 @@ const workflow = {
64
67
  },
65
68
  ],
66
69
  };
70
+ // !!
67
71
  function main() {
68
72
  return __awaiter(this, void 0, void 0, function* () {
69
73
  const worker = yield hatchet.worker('byo-logger-worker', 1);
@@ -19,7 +19,7 @@ const sleep = (ms) => new Promise((resolve) => {
19
19
  });
20
20
  function main() {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- hatchet.event.push('concurrency:create', {
22
+ hatchet.events.push('concurrency:create', {
23
23
  data: 'event 1',
24
24
  userId: 'user1',
25
25
  });
@@ -28,7 +28,7 @@ function main() {
28
28
  // before that will cancel
29
29
  // the first run and run the second event
30
30
  yield sleep(1000);
31
- hatchet.event.push('concurrency:create', {
31
+ hatchet.events.push('concurrency:create', {
32
32
  data: 'event 2',
33
33
  userId: 'user1',
34
34
  });
@@ -25,7 +25,7 @@ function main() {
25
25
  if (i > 10) {
26
26
  group = 1;
27
27
  }
28
- hatchet.event.push('concurrency:create', {
28
+ hatchet.events.push('concurrency:create', {
29
29
  data: `event ${i}`,
30
30
  group,
31
31
  });
@@ -21,7 +21,7 @@ function main() {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  // ? Create
23
23
  // You can create dynamic cron triggers programmatically via the API
24
- const createdCron = yield hatchet.cron.create(cron_worker_1.simpleCronWorkflow, // workflow object or string workflow id
24
+ const createdCron = yield hatchet.crons.create(cron_worker_1.simpleCronWorkflow, // workflow object or string workflow id
25
25
  {
26
26
  name: 'customer-a-daily-report', // friendly name for the cron trigger
27
27
  expression: '0 12 * * *', // every day at noon
@@ -36,16 +36,16 @@ function main() {
36
36
  // !!
37
37
  // ? Get
38
38
  // You can get a specific cron trigger by passing in the cron trigger id
39
- const cron = yield hatchet.cron.get(id);
39
+ const cron = yield hatchet.crons.get(id);
40
40
  // !!
41
41
  // ? Delete
42
42
  // You can delete a cron trigger by passing the cron object
43
43
  // or a cron Id to the delete method
44
- yield hatchet.cron.delete(cron);
44
+ yield hatchet.crons.delete(cron);
45
45
  // !!
46
46
  // ? List
47
47
  // You can list all cron triggers by passing in a query object
48
- const cronList = yield hatchet.cron.list({
48
+ const cronList = yield hatchet.crons.list({
49
49
  offset: 0,
50
50
  limit: 10,
51
51
  });
@@ -59,7 +59,6 @@ const workflow = {
59
59
  // simulate a really slow network call
60
60
  setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
61
61
  yield sleep(1000);
62
- ctx.playground('slow', 'call');
63
62
  }), 5000);
64
63
  return { step4: 'step4' };
65
64
  }),
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const sdk_1 = __importDefault(require("../sdk"));
7
7
  const hatchet = sdk_1.default.init();
8
8
  // Push a single event (example)
9
- hatchet.event.push('user:create', {
9
+ hatchet.events.push('user:create', {
10
10
  test: 'test',
11
11
  });
12
12
  // Example events to be pushed in bulk
@@ -25,7 +25,7 @@ const events = [
25
25
  },
26
26
  ];
27
27
  // Bulk push the events and compare the keys
28
- hatchet.event
28
+ hatchet.events
29
29
  .bulkPush('user:create:bulk', events)
30
30
  .then((result) => {
31
31
  const returnedEvents = result.events;
@@ -19,6 +19,7 @@ const hatchet = sdk_1.default.init({
19
19
  const sleep = (ms) => new Promise((resolve) => {
20
20
  setTimeout(resolve, ms);
21
21
  });
22
+ // ❓ Logger
22
23
  const workflow = {
23
24
  id: 'logger-example',
24
25
  description: 'test',
@@ -40,6 +41,7 @@ const workflow = {
40
41
  },
41
42
  ],
42
43
  };
44
+ // ‼️
43
45
  function main() {
44
46
  return __awaiter(this, void 0, void 0, function* () {
45
47
  const worker = yield hatchet.worker('logger-worker', 1);
@@ -41,7 +41,7 @@ const workflow = {
41
41
  // 👀 we can do things like perform cleanup logic
42
42
  // or notify a user here
43
43
  // 👀 you can access the error from the failed step(s) like this
44
- console.log(ctx.stepRunErrors());
44
+ console.log(ctx.errors());
45
45
  return { onFailure: 'step' };
46
46
  }),
47
47
  },
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const sdk_1 = __importDefault(require("../../sdk"));
7
7
  const hatchet = sdk_1.default.init();
8
- hatchet.event.push('rate-limit:create', {
8
+ hatchet.events.push('rate-limit:create', {
9
9
  test: '1',
10
10
  });
11
- hatchet.event.push('rate-limit:create', {
11
+ hatchet.events.push('rate-limit:create', {
12
12
  test: '2',
13
13
  });
14
- hatchet.event.push('rate-limit:create', {
14
+ hatchet.events.push('rate-limit:create', {
15
15
  test: '3',
16
16
  });
@@ -21,7 +21,7 @@ function main() {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  // ? Create
23
23
  // You can create dynamic scheduled runs programmatically via the API
24
- const createdScheduledRun = yield hatchet.schedule.create(simple_worker_1.simpleWorkflow, // workflow object or string workflow id
24
+ const createdScheduledRun = yield hatchet.schedules.create(simple_worker_1.simpleWorkflow, // workflow object or string workflow id
25
25
  {
26
26
  triggerAt: new Date(Date.now() + 1000 * 60 * 60 * 24), // 24 hours from now
27
27
  input: {
@@ -35,16 +35,16 @@ function main() {
35
35
  // !!
36
36
  // ? Get
37
37
  // You can get a specific scheduled run by passing in the scheduled run id
38
- const scheduledRun = yield hatchet.schedule.get(id);
38
+ const scheduledRun = yield hatchet.schedules.get(id);
39
39
  // !!
40
40
  // ? Delete
41
41
  // You can delete a scheduled run by passing the scheduled run object
42
42
  // or a scheduled run Id to the delete method
43
- yield hatchet.schedule.delete(scheduledRun);
43
+ yield hatchet.schedules.delete(scheduledRun);
44
44
  // !!
45
45
  // ? List
46
46
  // You can list all scheduled runs by passing in a query object
47
- const scheduledRunList = yield hatchet.schedule.list({
47
+ const scheduledRunList = yield hatchet.schedules.list({
48
48
  offset: 0,
49
49
  limit: 10,
50
50
  });
@@ -28,9 +28,9 @@ const workflow = {
28
28
  // eslint-disable-next-line no-plusplus
29
29
  for (let i = 0; i < count; i++) {
30
30
  const result = yield ctx.spawnWorkflow(childWorkflow, {}, { sticky: true });
31
- results.push(result.result());
31
+ results.push(result.output);
32
32
  const result2 = yield ctx.spawnWorkflow(softChildWorkflow, {}, { sticky: true });
33
- results.push(result2.result());
33
+ results.push(result2.output);
34
34
  }
35
35
  console.log('Spawned ', count, ' child workflows of each type');
36
36
  console.log('Results:', yield Promise.all(results));
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sdk_1 = __importDefault(require("../sdk"));
16
16
  const workflow_1 = require("../workflow");
17
17
  const hatchet = sdk_1.default.init();
18
+ // ❓ StickyWorker
18
19
  const workflow = {
19
20
  id: 'sticky-workflow',
20
21
  description: 'test',
@@ -35,9 +36,12 @@ const workflow = {
35
36
  },
36
37
  ],
37
38
  };
39
+ // ‼️
40
+ // ❓ StickyChild
38
41
  const childWorkflow = {
39
42
  id: 'child-sticky-workflow',
40
43
  description: 'test',
44
+ // 👀 Specify a sticky strategy when declaring the workflow
41
45
  sticky: workflow_1.StickyStrategy.HARD,
42
46
  steps: [
43
47
  {
@@ -58,6 +62,7 @@ const childWorkflow = {
58
62
  },
59
63
  ],
60
64
  };
65
+ // ‼️
61
66
  function main() {
62
67
  return __awaiter(this, void 0, void 0, function* () {
63
68
  const worker1 = yield hatchet.worker('sticky-worker-1');
package/index.d.ts CHANGED
@@ -5,8 +5,6 @@ export * from './clients/worker';
5
5
  export * from './clients/rest';
6
6
  export * from './clients/admin';
7
7
  export * from './util/workflow-run-ref';
8
- export * from './v1/client/client';
9
- export * from './v1/client/worker';
10
- export * from './v1/workflow';
8
+ export * from './v1';
11
9
  export default Hatchet;
12
10
  export { Hatchet };
package/index.js CHANGED
@@ -23,7 +23,5 @@ __exportStar(require("./clients/worker"), exports);
23
23
  __exportStar(require("./clients/rest"), exports);
24
24
  __exportStar(require("./clients/admin"), exports);
25
25
  __exportStar(require("./util/workflow-run-ref"), exports);
26
- __exportStar(require("./v1/client/client"), exports);
27
- __exportStar(require("./v1/client/worker"), exports);
28
- __exportStar(require("./v1/workflow"), exports);
26
+ __exportStar(require("./v1"), exports);
29
27
  exports.default = client_1.HatchetClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.0.0-alpha1",
3
+ "version": "1.0.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "url": "https://github.com/hatchet-dev/hatchet-typescript.git"
16
16
  },
17
17
  "scripts": {
18
- "build": "echo 'build hatchet sdk with `npn run tsc:build` to ensure it is not build during the publish step' && exit 0",
18
+ "build": "echo 'build hatchet sdk with `npm run tsc:build` to ensure it is not build during the publish step' && exit 0",
19
19
  "prepare": "npm run build",
20
20
  "dump-version": "node -e \"console.log('export const HATCHET_VERSION = \\'' + require('./package.json').version + '\\';');\" > src/version.ts",
21
21
  "tsc:build": "npm run dump-version && tsc && resolve-tspaths",
@@ -130,6 +130,8 @@ export interface AssignedAction {
130
130
  workflowRunId: string;
131
131
  /** the get group key run id (optional) */
132
132
  getGroupKeyRunId: string;
133
+ /** task id */
134
+ taskId?: number;
133
135
  /** the job id */
134
136
  jobId: string;
135
137
  /** the job name */
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.0
4
+ // protoc-gen-ts_proto v2.6.1
5
5
  // protoc v3.19.1
6
6
  // source: dispatcher/dispatcher.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.0
4
+ // protoc-gen-ts_proto v2.6.1
5
5
  // protoc v3.19.1
6
6
  // source: events/events.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.0
4
+ // protoc-gen-ts_proto v2.6.1
5
5
  // protoc v3.19.1
6
6
  // source: google/protobuf/timestamp.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });