@hatchet-dev/typescript-sdk 0.8.0-alpha.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/admin/admin-client.d.ts +13 -8
- package/clients/admin/admin-client.js +23 -23
- package/clients/dispatcher/action-listener.d.ts +3 -60
- package/clients/dispatcher/action-listener.js +1 -18
- package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.js +1 -7
- package/clients/listener/child-listener-client.d.ts +0 -1
- package/clients/listener/listener-client.d.ts +6 -14
- package/clients/listener/listener-client.js +16 -85
- package/clients/rest/generated/Api.d.ts +2 -19
- package/clients/rest/generated/Api.js +0 -17
- package/clients/rest/generated/data-contracts.d.ts +0 -25
- package/clients/rest/generated/http-client.js +2 -2
- package/clients/worker/worker.d.ts +3 -10
- package/clients/worker/worker.js +153 -205
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/protoc/dispatcher/dispatcher.js +13 -13
- package/protoc/workflows/workflows.js +5 -5
- package/step.d.ts +11 -13
- package/step.js +13 -70
- package/util/config-loader/token.js +2 -3
- package/util/parse.js +1 -7
- package/util/retrier.js +1 -2
- package/util/thread-helper.d.ts +0 -1
- package/util/thread-helper.js +1 -2
- package/util/workflow-run-ref.d.ts +17 -0
- package/util/workflow-run-ref.js +94 -0
- package/clients/worker/handler.d.ts +0 -58
- package/clients/worker/handler.js +0 -191
|
@@ -49,8 +49,8 @@ class HttpClient {
|
|
|
49
49
|
this.setSecurityData = (data) => {
|
|
50
50
|
this.securityData = data;
|
|
51
51
|
};
|
|
52
|
-
this.request = (
|
|
53
|
-
var { secure, path, type, query, format, body } =
|
|
52
|
+
this.request = (_a) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
var { secure, path, type, query, format, body } = _a, params = __rest(_a, ["secure", "path", "type", "query", "format", "body"]);
|
|
54
54
|
const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
|
|
55
55
|
this.securityWorker &&
|
|
56
56
|
(yield this.securityWorker(this.securityData))) ||
|
|
@@ -4,8 +4,6 @@ import { StepActionEvent, StepActionEventType, GroupKeyActionEvent, GroupKeyActi
|
|
|
4
4
|
import HatchetPromise from '../../util/hatchet-promise/hatchet-promise';
|
|
5
5
|
import { Workflow } from '../../workflow';
|
|
6
6
|
import { Logger } from '../../util/logger';
|
|
7
|
-
import { WebhookHandler } from './handler';
|
|
8
|
-
import { WebhookWorkerCreateRequest } from '../rest/generated/data-contracts';
|
|
9
7
|
import { Context, StepRunFunction } from '../../step';
|
|
10
8
|
export type ActionRegistry = Record<Action['actionId'], Function>;
|
|
11
9
|
export declare class Worker {
|
|
@@ -20,28 +18,23 @@ export declare class Worker {
|
|
|
20
18
|
maxRuns?: number;
|
|
21
19
|
logger: Logger;
|
|
22
20
|
registeredWorkflowPromises: Array<Promise<any>>;
|
|
23
|
-
registeredWorkflowIds: string[];
|
|
24
21
|
constructor(client: HatchetClient, options: {
|
|
25
22
|
name: string;
|
|
26
23
|
handleKill?: boolean;
|
|
27
24
|
maxRuns?: number;
|
|
28
25
|
});
|
|
29
|
-
private registerActions;
|
|
30
|
-
getHandler(workflows: Workflow[]): WebhookHandler;
|
|
31
|
-
registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorker, any>>;
|
|
32
26
|
/**
|
|
33
27
|
* @deprecated use registerWorkflow instead
|
|
34
28
|
*/
|
|
35
29
|
register_workflow(initWorkflow: Workflow): Promise<void>;
|
|
36
30
|
registerWorkflow(initWorkflow: Workflow): Promise<void>;
|
|
37
31
|
registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
|
|
38
|
-
handleStartStepRun(action: Action):
|
|
39
|
-
handleStartGroupKeyRun(action: Action):
|
|
32
|
+
handleStartStepRun(action: Action): void;
|
|
33
|
+
handleStartGroupKeyRun(action: Action): void;
|
|
40
34
|
getStepActionEvent(action: Action, eventType: StepActionEventType, payload?: any): StepActionEvent;
|
|
41
35
|
getGroupKeyActionEvent(action: Action, eventType: GroupKeyActionEventType, payload?: any): GroupKeyActionEvent;
|
|
42
|
-
handleCancelStepRun(action: Action):
|
|
36
|
+
handleCancelStepRun(action: Action): void;
|
|
43
37
|
stop(): Promise<void>;
|
|
44
38
|
exitGracefully(handleKill: boolean): Promise<void>;
|
|
45
39
|
start(): Promise<void>;
|
|
46
|
-
handleAction(action: Action): Promise<void>;
|
|
47
40
|
}
|
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,33 +42,6 @@ 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
|
-
registerActions(workflow) {
|
|
47
|
-
var _a;
|
|
48
|
-
const newActions = workflow.steps.reduce((acc, step) => {
|
|
49
|
-
acc[`${workflow.id}:${step.name}`] = step.run;
|
|
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(workflows) {
|
|
62
|
-
for (const workflow of workflows) {
|
|
63
|
-
const wf = Object.assign(Object.assign({}, workflow), { id: this.client.config.namespace + workflow.id });
|
|
64
|
-
this.registerActions(wf);
|
|
65
|
-
}
|
|
66
|
-
return new handler_1.WebhookHandler(this, workflows);
|
|
67
|
-
}
|
|
68
|
-
registerWebhook(webhook) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
return this.client.admin.webhook_create(Object.assign(Object.assign({}, webhook), { workflows: this.registeredWorkflowIds }));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
45
|
/**
|
|
74
46
|
* @deprecated use registerWorkflow instead
|
|
75
47
|
*/
|
|
@@ -80,7 +52,7 @@ class Worker {
|
|
|
80
52
|
}
|
|
81
53
|
registerWorkflow(initWorkflow) {
|
|
82
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var _a, _b;
|
|
55
|
+
var _a, _b, _c;
|
|
84
56
|
const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
|
|
85
57
|
try {
|
|
86
58
|
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
@@ -108,7 +80,6 @@ class Worker {
|
|
|
108
80
|
],
|
|
109
81
|
}
|
|
110
82
|
: undefined;
|
|
111
|
-
this.registeredWorkflowIds.push(workflow.id);
|
|
112
83
|
const registeredWorkflow = this.client.admin.putWorkflow({
|
|
113
84
|
name: workflow.id,
|
|
114
85
|
description: workflow.description,
|
|
@@ -147,154 +118,145 @@ class Worker {
|
|
|
147
118
|
catch (e) {
|
|
148
119
|
throw new hatchet_error_1.default(`Could not register workflow: ${e.message}`);
|
|
149
120
|
}
|
|
150
|
-
|
|
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);
|
|
151
133
|
});
|
|
152
134
|
}
|
|
153
135
|
registerAction(actionId, action) {
|
|
154
136
|
this.action_registry[actionId] = action;
|
|
155
137
|
}
|
|
156
138
|
handleStartStepRun(action) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// delete the run from the futures
|
|
177
|
-
delete this.futures[action.stepRunId];
|
|
178
|
-
}
|
|
179
|
-
catch (actionEventError) {
|
|
180
|
-
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}`);
|
|
181
158
|
// send a failure event
|
|
182
|
-
const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
catch (failureEventError) {
|
|
187
|
-
this.logger.error(`Could not send failed action event: ${failureEventError.message}`);
|
|
188
|
-
}
|
|
189
|
-
this.logger.error(`Could not send action event: ${actionEventError.message}`);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
const failure = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
|
|
194
|
-
if (error.stack) {
|
|
195
|
-
this.logger.error(error.stack);
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
// Send the action event to the dispatcher
|
|
199
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, {
|
|
200
|
-
message: error === null || error === void 0 ? void 0 : error.message,
|
|
201
|
-
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}`);
|
|
202
162
|
});
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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) => {
|
|
208
183
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
result = yield run();
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
yield failure(e);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
yield success(result);
|
|
221
|
-
}))());
|
|
222
|
-
this.futures[action.stepRunId] = future;
|
|
223
|
-
// Send the action event to the dispatcher
|
|
224
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
|
|
225
|
-
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) {
|
|
226
189
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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) => {
|
|
231
197
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
202
|
+
}
|
|
234
203
|
}
|
|
235
204
|
handleStartGroupKeyRun(action) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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];
|
|
244
229
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const step = this.action_registry[actionId];
|
|
248
|
-
if (!step) {
|
|
249
|
-
this.logger.error(`Could not find step '${actionId}'`);
|
|
250
|
-
return;
|
|
230
|
+
catch (e) {
|
|
231
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
251
232
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
260
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
261
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
262
|
-
});
|
|
263
|
-
// delete the run from the futures
|
|
264
|
-
delete this.futures[key];
|
|
265
|
-
}
|
|
266
|
-
catch (e) {
|
|
267
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
const failure = (error) => {
|
|
271
|
-
this.logger.error(`Step run ${key} failed: ${error.message}`);
|
|
272
|
-
try {
|
|
273
|
-
// Send the action event to the dispatcher
|
|
274
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
275
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
276
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
277
|
-
});
|
|
278
|
-
// delete the run from the futures
|
|
279
|
-
delete this.futures[key];
|
|
280
|
-
}
|
|
281
|
-
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) => {
|
|
282
240
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_STARTED);
|
|
289
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
|
|
241
|
+
});
|
|
242
|
+
// delete the run from the futures
|
|
243
|
+
delete this.futures[key];
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
290
246
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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) => {
|
|
295
254
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
259
|
+
}
|
|
298
260
|
}
|
|
299
261
|
getStepActionEvent(action, eventType, payload = '') {
|
|
300
262
|
return {
|
|
@@ -310,9 +272,6 @@ class Worker {
|
|
|
310
272
|
};
|
|
311
273
|
}
|
|
312
274
|
getGroupKeyActionEvent(action, eventType, payload = '') {
|
|
313
|
-
if (!action.getGroupKeyRunId) {
|
|
314
|
-
throw new hatchet_error_1.default('No group key run id provided');
|
|
315
|
-
}
|
|
316
275
|
return {
|
|
317
276
|
workerId: this.name,
|
|
318
277
|
workflowRunId: action.workflowRunId,
|
|
@@ -324,29 +283,26 @@ class Worker {
|
|
|
324
283
|
};
|
|
325
284
|
}
|
|
326
285
|
handleCancelStepRun(action) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
delete this.contexts[stepRunId];
|
|
336
|
-
}
|
|
337
|
-
if (future) {
|
|
338
|
-
future.promise.catch(() => {
|
|
339
|
-
this.logger.info(`Cancelled step run ${action.stepRunId}`);
|
|
340
|
-
});
|
|
341
|
-
future.cancel('Cancelled by worker');
|
|
342
|
-
yield future.promise;
|
|
343
|
-
delete this.futures[stepRunId];
|
|
344
|
-
}
|
|
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];
|
|
345
294
|
}
|
|
346
|
-
|
|
347
|
-
|
|
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];
|
|
348
301
|
}
|
|
349
|
-
}
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
this.logger.error(`Could not cancel step run: ${e.message}`);
|
|
305
|
+
}
|
|
350
306
|
}
|
|
351
307
|
stop() {
|
|
352
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -394,7 +350,18 @@ class Worker {
|
|
|
394
350
|
_d = false;
|
|
395
351
|
const action = _c;
|
|
396
352
|
this.logger.info(`Worker ${this.name} received action ${action.actionId}:${action.actionType}`);
|
|
397
|
-
|
|
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
|
+
}
|
|
398
365
|
}
|
|
399
366
|
}
|
|
400
367
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -416,24 +383,5 @@ class Worker {
|
|
|
416
383
|
}
|
|
417
384
|
});
|
|
418
385
|
}
|
|
419
|
-
handleAction(action) {
|
|
420
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
421
|
-
const type = action.actionType
|
|
422
|
-
? (0, dispatcher_1.actionTypeFromJSON)(action.actionType)
|
|
423
|
-
: dispatcher_1.ActionType.START_STEP_RUN;
|
|
424
|
-
if (type === dispatcher_1.ActionType.START_STEP_RUN) {
|
|
425
|
-
yield this.handleStartStepRun(action);
|
|
426
|
-
}
|
|
427
|
-
else if (type === dispatcher_1.ActionType.CANCEL_STEP_RUN) {
|
|
428
|
-
yield this.handleCancelStepRun(action);
|
|
429
|
-
}
|
|
430
|
-
else if (type === dispatcher_1.ActionType.START_GET_GROUP_KEY) {
|
|
431
|
-
yield this.handleStartGroupKeyRun(action);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
this.logger.error(`Worker ${this.name} received unknown action type ${type}`);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
386
|
}
|
|
439
387
|
exports.Worker = Worker;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -20,4 +20,5 @@ __exportStar(require("./step"), exports);
|
|
|
20
20
|
__exportStar(require("./clients/worker"), exports);
|
|
21
21
|
__exportStar(require("./clients/rest"), exports);
|
|
22
22
|
__exportStar(require("./clients/admin"), exports);
|
|
23
|
+
__exportStar(require("./util/workflow-run-ref"), exports);
|
|
23
24
|
exports.default = hatchet_client_1.HatchetClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"worker:logger": "npm run exec -- ./examples/logger.ts",
|
|
52
52
|
"api": "npm run exec -- ./examples/api.ts",
|
|
53
53
|
"prepublish": "cp package.json dist/package.json;",
|
|
54
|
-
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks
|
|
54
|
+
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
|
|
55
55
|
"generate-docs": "typedoc"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [],
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"ts-jest": "^29.1.1",
|
|
85
85
|
"ts-node": "^10.9.2",
|
|
86
86
|
"ts-proto": "^1.167.0",
|
|
87
|
-
"typedoc": "^0.
|
|
87
|
+
"typedoc": "^0.26.2",
|
|
88
88
|
"typedoc-plugin-markdown": "^4.0.2",
|
|
89
89
|
"typescript": "^5.3.3"
|
|
90
90
|
},
|