@hatchet-dev/typescript-sdk 0.8.0-alpha.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/admin/admin-client.d.ts +73 -12
- package/clients/admin/admin-client.js +89 -13
- package/clients/dispatcher/action-listener.d.ts +3 -60
- package/clients/dispatcher/action-listener.js +1 -18
- package/clients/hatchet-client/hatchet-client.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.js +0 -6
- package/clients/rest/generated/Api.d.ts +1 -18
- package/clients/rest/generated/Api.js +0 -17
- package/clients/rest/generated/data-contracts.d.ts +0 -25
- package/clients/worker/worker.d.ts +7 -11
- package/clients/worker/worker.js +163 -208
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/workflows/workflows.js +1 -1
- package/step.d.ts +1 -1
- package/step.js +1 -1
- package/util/parse.js +0 -5
- package/workflow.d.ts +12 -12
- package/workflow.js +1 -1
- package/clients/worker/handler.d.ts +0 -56
- package/clients/worker/handler.js +0 -160
package/clients/worker/worker.js
CHANGED
|
@@ -25,14 +25,13 @@ 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 logger_1 = require("../../util/logger");
|
|
28
|
-
|
|
28
|
+
// import sleep from '../../util/sleep.js';
|
|
29
29
|
const step_1 = require("../../step");
|
|
30
30
|
class Worker {
|
|
31
31
|
constructor(client, options) {
|
|
32
32
|
this.futures = {};
|
|
33
33
|
this.contexts = {};
|
|
34
34
|
this.registeredWorkflowPromises = [];
|
|
35
|
-
this.registeredWorkflowIds = [];
|
|
36
35
|
this.client = client;
|
|
37
36
|
this.name = this.client.config.namespace + options.name;
|
|
38
37
|
this.action_registry = {};
|
|
@@ -43,40 +42,17 @@ class Worker {
|
|
|
43
42
|
this.handle_kill = options.handleKill === undefined ? true : options.handleKill;
|
|
44
43
|
this.logger = new logger_1.Logger(`Worker/${this.name}`, this.client.config.log_level);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
const onFailureAction = workflow.onFailure
|
|
53
|
-
? {
|
|
54
|
-
[`${workflow.id}-on-failure:${workflow.onFailure.name}`]: workflow.onFailure.run,
|
|
55
|
-
}
|
|
56
|
-
: {};
|
|
57
|
-
this.action_registry = Object.assign(Object.assign(Object.assign({}, this.action_registry), newActions), onFailureAction);
|
|
58
|
-
this.action_registry = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
59
|
-
? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
60
|
-
}
|
|
61
|
-
getHandler(workflow) {
|
|
62
|
-
const wf = Object.assign(Object.assign({}, workflow), { id: this.client.config.namespace + workflow.id });
|
|
63
|
-
this.registerActions(wf);
|
|
64
|
-
return new handler_1.WebhookHandler(this);
|
|
65
|
-
}
|
|
66
|
-
registerWebhook(webhook) {
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use registerWorkflow instead
|
|
47
|
+
*/
|
|
48
|
+
register_workflow(initWorkflow) {
|
|
67
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return this.
|
|
50
|
+
return this.registerWorkflow(initWorkflow);
|
|
69
51
|
});
|
|
70
52
|
}
|
|
71
|
-
// @deprecated
|
|
72
53
|
registerWorkflow(initWorkflow) {
|
|
73
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
register_workflow(initWorkflow) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
var _a, _b;
|
|
55
|
+
var _a, _b, _c;
|
|
80
56
|
const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
|
|
81
57
|
try {
|
|
82
58
|
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
@@ -104,13 +80,14 @@ class Worker {
|
|
|
104
80
|
],
|
|
105
81
|
}
|
|
106
82
|
: undefined;
|
|
107
|
-
this.
|
|
108
|
-
const registeredWorkflow = this.client.admin.put_workflow({
|
|
83
|
+
const registeredWorkflow = this.client.admin.putWorkflow({
|
|
109
84
|
name: workflow.id,
|
|
110
85
|
description: workflow.description,
|
|
111
86
|
version: workflow.version || '',
|
|
112
|
-
eventTriggers: workflow.on
|
|
113
|
-
|
|
87
|
+
eventTriggers: workflow.on && workflow.on.event
|
|
88
|
+
? [this.client.config.namespace + workflow.on.event]
|
|
89
|
+
: [],
|
|
90
|
+
cronTriggers: workflow.on && workflow.on.cron ? [workflow.on.cron] : [],
|
|
114
91
|
scheduledTriggers: [],
|
|
115
92
|
concurrency,
|
|
116
93
|
scheduleTimeout: workflow.scheduleTimeout,
|
|
@@ -141,153 +118,145 @@ class Worker {
|
|
|
141
118
|
catch (e) {
|
|
142
119
|
throw new hatchet_error_1.default(`Could not register workflow: ${e.message}`);
|
|
143
120
|
}
|
|
144
|
-
|
|
121
|
+
const newActions = workflow.steps.reduce((acc, step) => {
|
|
122
|
+
acc[`${workflow.id}:${step.name}`] = step.run;
|
|
123
|
+
return acc;
|
|
124
|
+
}, {});
|
|
125
|
+
const onFailureAction = workflow.onFailure
|
|
126
|
+
? {
|
|
127
|
+
[`${workflow.id}-on-failure:${workflow.onFailure.name}`]: workflow.onFailure.run,
|
|
128
|
+
}
|
|
129
|
+
: {};
|
|
130
|
+
this.action_registry = Object.assign(Object.assign(Object.assign({}, this.action_registry), newActions), onFailureAction);
|
|
131
|
+
this.action_registry = ((_c = workflow.concurrency) === null || _c === void 0 ? void 0 : _c.name)
|
|
132
|
+
? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
145
133
|
});
|
|
146
134
|
}
|
|
147
135
|
registerAction(actionId, action) {
|
|
148
136
|
this.action_registry[actionId] = action;
|
|
149
137
|
}
|
|
150
138
|
handleStartStepRun(action) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// delete the run from the futures
|
|
171
|
-
delete this.futures[action.stepRunId];
|
|
172
|
-
}
|
|
173
|
-
catch (actionEventError) {
|
|
174
|
-
this.logger.error(`Could not send completed action event: ${actionEventError.message}`);
|
|
139
|
+
const { actionId } = action;
|
|
140
|
+
try {
|
|
141
|
+
const context = new step_1.Context(action, this.client);
|
|
142
|
+
this.contexts[action.stepRunId] = context;
|
|
143
|
+
const step = this.action_registry[actionId];
|
|
144
|
+
if (!step) {
|
|
145
|
+
this.logger.error(`Could not find step '${actionId}'`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
return step(context);
|
|
150
|
+
});
|
|
151
|
+
const success = (result) => {
|
|
152
|
+
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
153
|
+
try {
|
|
154
|
+
// Send the action event to the dispatcher
|
|
155
|
+
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result || null);
|
|
156
|
+
this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
|
|
157
|
+
this.logger.error(`Could not send completed action event: ${e.message}`);
|
|
175
158
|
// send a failure event
|
|
176
|
-
const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
catch (failureEventError) {
|
|
181
|
-
this.logger.error(`Could not send failed action event: ${failureEventError.message}`);
|
|
182
|
-
}
|
|
183
|
-
this.logger.error(`Could not send action event: ${actionEventError.message}`);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
const failure = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
|
|
188
|
-
if (error.stack) {
|
|
189
|
-
this.logger.error(error.stack);
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
// Send the action event to the dispatcher
|
|
193
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, {
|
|
194
|
-
message: error === null || error === void 0 ? void 0 : error.message,
|
|
195
|
-
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
159
|
+
const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, e.message);
|
|
160
|
+
this.client.dispatcher.sendStepActionEvent(failureEvent).catch((err2) => {
|
|
161
|
+
this.logger.error(`Could not send failed action event: ${err2.message}`);
|
|
196
162
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
163
|
+
});
|
|
164
|
+
// delete the run from the futures
|
|
165
|
+
delete this.futures[action.stepRunId];
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const failure = (error) => {
|
|
172
|
+
this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
|
|
173
|
+
if (error.stack) {
|
|
174
|
+
this.logger.error(error.stack);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
// Send the action event to the dispatcher
|
|
178
|
+
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, {
|
|
179
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
180
|
+
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
181
|
+
});
|
|
182
|
+
this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
|
|
202
183
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
catch (e) {
|
|
210
|
-
yield failure(e);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
yield success(null);
|
|
214
|
-
}))());
|
|
215
|
-
this.futures[action.stepRunId] = future;
|
|
216
|
-
// Send the action event to the dispatcher
|
|
217
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
|
|
218
|
-
this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
|
|
184
|
+
});
|
|
185
|
+
// delete the run from the futures
|
|
186
|
+
delete this.futures[action.stepRunId];
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
219
189
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
193
|
+
this.futures[action.stepRunId] = future;
|
|
194
|
+
// Send the action event to the dispatcher
|
|
195
|
+
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
|
|
196
|
+
this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
|
|
224
197
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
202
|
+
}
|
|
227
203
|
}
|
|
228
204
|
handleStartGroupKeyRun(action) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
205
|
+
const { actionId } = action;
|
|
206
|
+
try {
|
|
207
|
+
const context = new step_1.Context(action, this.client);
|
|
208
|
+
const key = action.getGroupKeyRunId;
|
|
209
|
+
this.contexts[key] = context;
|
|
210
|
+
this.logger.debug(`Starting group key run ${key}`);
|
|
211
|
+
const step = this.action_registry[actionId];
|
|
212
|
+
if (!step) {
|
|
213
|
+
this.logger.error(`Could not find step '${actionId}'`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
return step(context);
|
|
218
|
+
});
|
|
219
|
+
const success = (result) => {
|
|
220
|
+
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
221
|
+
try {
|
|
222
|
+
// Send the action event to the dispatcher
|
|
223
|
+
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
224
|
+
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
225
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
226
|
+
});
|
|
227
|
+
// delete the run from the futures
|
|
228
|
+
delete this.futures[key];
|
|
237
229
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const step = this.action_registry[actionId];
|
|
241
|
-
if (!step) {
|
|
242
|
-
this.logger.error(`Could not find step '${actionId}'`);
|
|
243
|
-
return;
|
|
230
|
+
catch (e) {
|
|
231
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
244
232
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
253
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
254
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
255
|
-
});
|
|
256
|
-
// delete the run from the futures
|
|
257
|
-
delete this.futures[key];
|
|
258
|
-
}
|
|
259
|
-
catch (e) {
|
|
260
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
const failure = (error) => {
|
|
264
|
-
this.logger.error(`Step run ${key} failed: ${error.message}`);
|
|
265
|
-
try {
|
|
266
|
-
// Send the action event to the dispatcher
|
|
267
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
268
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
269
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
270
|
-
});
|
|
271
|
-
// delete the run from the futures
|
|
272
|
-
delete this.futures[key];
|
|
273
|
-
}
|
|
274
|
-
catch (e) {
|
|
233
|
+
};
|
|
234
|
+
const failure = (error) => {
|
|
235
|
+
this.logger.error(`Step run ${key} failed: ${error.message}`);
|
|
236
|
+
try {
|
|
237
|
+
// Send the action event to the dispatcher
|
|
238
|
+
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
239
|
+
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
275
240
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_STARTED);
|
|
282
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
241
|
+
});
|
|
242
|
+
// delete the run from the futures
|
|
243
|
+
delete this.futures[key];
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
283
246
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
250
|
+
this.futures[action.getGroupKeyRunId] = future;
|
|
251
|
+
// Send the action event to the dispatcher
|
|
252
|
+
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_STARTED);
|
|
253
|
+
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
288
254
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
259
|
+
}
|
|
291
260
|
}
|
|
292
261
|
getStepActionEvent(action, eventType, payload = '') {
|
|
293
262
|
return {
|
|
@@ -303,9 +272,6 @@ class Worker {
|
|
|
303
272
|
};
|
|
304
273
|
}
|
|
305
274
|
getGroupKeyActionEvent(action, eventType, payload = '') {
|
|
306
|
-
if (!action.getGroupKeyRunId) {
|
|
307
|
-
throw new hatchet_error_1.default('No group key run id provided');
|
|
308
|
-
}
|
|
309
275
|
return {
|
|
310
276
|
workerId: this.name,
|
|
311
277
|
workflowRunId: action.workflowRunId,
|
|
@@ -317,29 +283,26 @@ class Worker {
|
|
|
317
283
|
};
|
|
318
284
|
}
|
|
319
285
|
handleCancelStepRun(action) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
delete this.contexts[stepRunId];
|
|
329
|
-
}
|
|
330
|
-
if (future) {
|
|
331
|
-
future.promise.catch(() => {
|
|
332
|
-
this.logger.info(`Cancelled step run ${action.stepRunId}`);
|
|
333
|
-
});
|
|
334
|
-
future.cancel('Cancelled by worker');
|
|
335
|
-
yield future.promise;
|
|
336
|
-
delete this.futures[stepRunId];
|
|
337
|
-
}
|
|
286
|
+
try {
|
|
287
|
+
this.logger.info(`Cancelling step run ${action.stepRunId}`);
|
|
288
|
+
const { stepRunId } = action;
|
|
289
|
+
const future = this.futures[stepRunId];
|
|
290
|
+
const context = this.contexts[stepRunId];
|
|
291
|
+
if (context && context.controller) {
|
|
292
|
+
context.controller.abort('Cancelled by worker');
|
|
293
|
+
delete this.contexts[stepRunId];
|
|
338
294
|
}
|
|
339
|
-
|
|
340
|
-
|
|
295
|
+
if (future) {
|
|
296
|
+
future.promise.catch(() => {
|
|
297
|
+
this.logger.info(`Cancelled step run ${action.stepRunId}`);
|
|
298
|
+
});
|
|
299
|
+
future.cancel('Cancelled by worker');
|
|
300
|
+
delete this.futures[stepRunId];
|
|
341
301
|
}
|
|
342
|
-
}
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
this.logger.error(`Could not cancel step run: ${e.message}`);
|
|
305
|
+
}
|
|
343
306
|
}
|
|
344
307
|
stop() {
|
|
345
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -387,7 +350,18 @@ class Worker {
|
|
|
387
350
|
_d = false;
|
|
388
351
|
const action = _c;
|
|
389
352
|
this.logger.info(`Worker ${this.name} received action ${action.actionId}:${action.actionType}`);
|
|
390
|
-
|
|
353
|
+
if (action.actionType === dispatcher_1.ActionType.START_STEP_RUN) {
|
|
354
|
+
this.handleStartStepRun(action);
|
|
355
|
+
}
|
|
356
|
+
else if (action.actionType === dispatcher_1.ActionType.CANCEL_STEP_RUN) {
|
|
357
|
+
this.handleCancelStepRun(action);
|
|
358
|
+
}
|
|
359
|
+
else if (action.actionType === dispatcher_1.ActionType.START_GET_GROUP_KEY) {
|
|
360
|
+
this.handleStartGroupKeyRun(action);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.logger.error(`Worker ${this.name} received unknown action type ${action.actionType}`);
|
|
364
|
+
}
|
|
391
365
|
}
|
|
392
366
|
}
|
|
393
367
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -409,24 +383,5 @@ class Worker {
|
|
|
409
383
|
}
|
|
410
384
|
});
|
|
411
385
|
}
|
|
412
|
-
handleAction(action) {
|
|
413
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
-
const type = action.actionType
|
|
415
|
-
? (0, dispatcher_1.actionTypeFromJSON)(action.actionType)
|
|
416
|
-
: dispatcher_1.ActionType.START_STEP_RUN;
|
|
417
|
-
if (type === dispatcher_1.ActionType.START_STEP_RUN) {
|
|
418
|
-
yield this.handleStartStepRun(action);
|
|
419
|
-
}
|
|
420
|
-
else if (type === dispatcher_1.ActionType.CANCEL_STEP_RUN) {
|
|
421
|
-
yield this.handleCancelStepRun(action);
|
|
422
|
-
}
|
|
423
|
-
else if (type === dispatcher_1.ActionType.START_GET_GROUP_KEY) {
|
|
424
|
-
yield this.handleStartGroupKeyRun(action);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
this.logger.error(`Worker ${this.name} received unknown action type ${type}`);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
386
|
}
|
|
432
387
|
exports.Worker = Worker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepare": "npm run build",
|
|
20
20
|
"tsc:build": "tsc && resolve-tspaths",
|
|
21
21
|
"test:unit": "jest --testMatch='**/*.test.ts'",
|
|
22
|
-
"test:e2e": "jest --testMatch='**/*.e2e.ts'
|
|
22
|
+
"test:e2e": "jest --testMatch='**/*.e2e.ts'",
|
|
23
23
|
"test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
|
|
24
24
|
"generate": "pnpm run '/generate-.*/'",
|
|
25
25
|
"generate-api": "npx --yes swagger-cli bundle ./hatchet/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
|
|
@@ -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 v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: dispatcher/dispatcher.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
package/protoc/events/events.js
CHANGED
|
@@ -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 v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: events/events.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -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 v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: google/protobuf/timestamp.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -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 v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: workflows/workflows.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
package/step.d.ts
CHANGED
package/step.js
CHANGED
|
@@ -229,7 +229,7 @@ class Context {
|
|
|
229
229
|
spawnWorkflow(workflowName, input, key) {
|
|
230
230
|
const { workflowRunId, stepRunId } = this.action;
|
|
231
231
|
const name = this.client.config.namespace + workflowName;
|
|
232
|
-
const childWorkflowRunIdPromise = this.client.admin.
|
|
232
|
+
const childWorkflowRunIdPromise = this.client.admin.runWorkflow(name, input, {
|
|
233
233
|
parentId: workflowRunId,
|
|
234
234
|
parentStepRunId: stepRunId,
|
|
235
235
|
childKey: key,
|
package/util/parse.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseJSON = void 0;
|
|
4
4
|
function parseJSON(json) {
|
|
5
|
-
// TODO why is this needed?
|
|
6
|
-
if (json.startsWith('ey')) {
|
|
7
|
-
const decoded = Buffer.from(json, 'base64').toString('utf8');
|
|
8
|
-
return JSON.parse(decoded);
|
|
9
|
-
}
|
|
10
5
|
try {
|
|
11
6
|
const firstParse = JSON.parse(json);
|
|
12
7
|
// Hatchet engine versions <=0.14.0 return JSON as a quoted string which needs to be parsed again.
|
package/workflow.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
60
60
|
* @deprecated Workflow timeout is deprecated. Use step timeouts instead.
|
|
61
61
|
*/
|
|
62
62
|
timeout: z.ZodOptional<z.ZodString>;
|
|
63
|
-
on: z.ZodUnion<[z.ZodObject<{
|
|
63
|
+
on: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
64
64
|
cron: z.ZodString;
|
|
65
65
|
event: z.ZodUndefined;
|
|
66
66
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -78,7 +78,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
78
78
|
}, {
|
|
79
79
|
event: string;
|
|
80
80
|
cron?: undefined;
|
|
81
|
-
}>]
|
|
81
|
+
}>]>>;
|
|
82
82
|
steps: z.ZodArray<z.ZodObject<{
|
|
83
83
|
name: z.ZodString;
|
|
84
84
|
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -160,16 +160,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
160
160
|
}[] | undefined;
|
|
161
161
|
}[];
|
|
162
162
|
id: string;
|
|
163
|
-
|
|
163
|
+
version?: string | undefined;
|
|
164
|
+
scheduleTimeout?: string | undefined;
|
|
165
|
+
timeout?: string | undefined;
|
|
166
|
+
on?: {
|
|
164
167
|
cron: string;
|
|
165
168
|
event?: undefined;
|
|
166
169
|
} | {
|
|
167
170
|
event: string;
|
|
168
171
|
cron?: undefined;
|
|
169
|
-
};
|
|
170
|
-
version?: string | undefined;
|
|
171
|
-
scheduleTimeout?: string | undefined;
|
|
172
|
-
timeout?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
173
|
onFailure?: {
|
|
174
174
|
name: string;
|
|
175
175
|
timeout?: string | undefined;
|
|
@@ -193,16 +193,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
193
193
|
}[] | undefined;
|
|
194
194
|
}[];
|
|
195
195
|
id: string;
|
|
196
|
-
|
|
196
|
+
version?: string | undefined;
|
|
197
|
+
scheduleTimeout?: string | undefined;
|
|
198
|
+
timeout?: string | undefined;
|
|
199
|
+
on?: {
|
|
197
200
|
cron: string;
|
|
198
201
|
event?: undefined;
|
|
199
202
|
} | {
|
|
200
203
|
event: string;
|
|
201
204
|
cron?: undefined;
|
|
202
|
-
};
|
|
203
|
-
version?: string | undefined;
|
|
204
|
-
scheduleTimeout?: string | undefined;
|
|
205
|
-
timeout?: string | undefined;
|
|
205
|
+
} | undefined;
|
|
206
206
|
onFailure?: {
|
|
207
207
|
name: string;
|
|
208
208
|
timeout?: string | undefined;
|
package/workflow.js
CHANGED
|
@@ -35,7 +35,7 @@ const EventConfigSchema = z.object({
|
|
|
35
35
|
cron: z.undefined(),
|
|
36
36
|
event: z.string(),
|
|
37
37
|
});
|
|
38
|
-
const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
|
|
38
|
+
const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]).optional();
|
|
39
39
|
const StepsSchema = z.array(step_1.CreateStepSchema);
|
|
40
40
|
exports.ConcurrencyLimitStrategy = workflows_1.ConcurrencyLimitStrategy;
|
|
41
41
|
exports.WorkflowConcurrency = z.object({
|