@hatchet-dev/typescript-sdk 0.1.8 → 0.1.10
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/worker/worker.d.ts +0 -1
- package/clients/worker/worker.js +25 -19
- package/index.d.ts +3 -0
- package/index.js +17 -0
- package/package.json +1 -1
- package/step.d.ts +1 -0
- package/step.js +1 -0
- package/workflow.d.ts +3 -3
- package/workflow.js +1 -1
|
@@ -13,7 +13,6 @@ export declare class Worker {
|
|
|
13
13
|
killing: boolean;
|
|
14
14
|
handle_kill: boolean;
|
|
15
15
|
action_registry: ActionRegistry;
|
|
16
|
-
concurrency_action_registry: ActionRegistry;
|
|
17
16
|
listener: ActionListener | undefined;
|
|
18
17
|
futures: Record<Action['stepRunId'], HatchetPromise<any>>;
|
|
19
18
|
contexts: Record<Action['stepRunId'], Context<any>>;
|
package/clients/worker/worker.js
CHANGED
|
@@ -35,7 +35,6 @@ class Worker {
|
|
|
35
35
|
this.client = client;
|
|
36
36
|
this.name = options.name;
|
|
37
37
|
this.action_registry = {};
|
|
38
|
-
this.concurrency_action_registry = {};
|
|
39
38
|
process.on('SIGTERM', () => this.exitGracefully());
|
|
40
39
|
process.on('SIGINT', () => this.exitGracefully());
|
|
41
40
|
this.killing = false;
|
|
@@ -46,9 +45,9 @@ class Worker {
|
|
|
46
45
|
var _a, _b;
|
|
47
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
47
|
try {
|
|
49
|
-
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.
|
|
48
|
+
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
50
49
|
? {
|
|
51
|
-
action: `${this.serviceName}:${workflow.concurrency.
|
|
50
|
+
action: `${this.serviceName}:${workflow.concurrency.name}`,
|
|
52
51
|
maxRuns: workflow.concurrency.maxRuns || 1,
|
|
53
52
|
limitStrategy: workflow.concurrency.limitStrategy || workflows_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
|
54
53
|
}
|
|
@@ -87,11 +86,8 @@ class Worker {
|
|
|
87
86
|
acc[`${this.serviceName}:${step.name}`] = step.run;
|
|
88
87
|
return acc;
|
|
89
88
|
}, {});
|
|
90
|
-
this.
|
|
91
|
-
? {
|
|
92
|
-
[`${this.serviceName}:${workflow.concurrency.action}`]: workflow.concurrency.key,
|
|
93
|
-
}
|
|
94
|
-
: {};
|
|
89
|
+
this.action_registry = ((_b = workflow.concurrency) === null || _b === void 0 ? void 0 : _b.name)
|
|
90
|
+
? Object.assign(Object.assign({}, this.action_registry), { [`${this.serviceName}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
95
91
|
});
|
|
96
92
|
}
|
|
97
93
|
handleStartStepRun(action) {
|
|
@@ -148,6 +144,7 @@ class Worker {
|
|
|
148
144
|
const context = new step_1.Context(action.actionPayload);
|
|
149
145
|
const key = action.getGroupKeyRunId;
|
|
150
146
|
this.contexts[key] = context;
|
|
147
|
+
this.logger.debug(`Starting group key run ${key}`);
|
|
151
148
|
const step = this.action_registry[actionId];
|
|
152
149
|
if (!step) {
|
|
153
150
|
this.logger.error(`Could not find step '${actionId}'`);
|
|
@@ -218,17 +215,26 @@ class Worker {
|
|
|
218
215
|
};
|
|
219
216
|
}
|
|
220
217
|
handleCancelStepRun(action) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
218
|
+
try {
|
|
219
|
+
this.logger.info(`Cancelling step run ${action.stepRunId}`);
|
|
220
|
+
const { stepRunId } = action;
|
|
221
|
+
const future = this.futures[stepRunId];
|
|
222
|
+
const context = this.contexts[stepRunId];
|
|
223
|
+
// TODO send cancel signal to context
|
|
224
|
+
if (context && context.controller) {
|
|
225
|
+
context.controller.abort('Cancelled by worker');
|
|
226
|
+
delete this.contexts[stepRunId];
|
|
227
|
+
}
|
|
228
|
+
if (future) {
|
|
229
|
+
future.promise.catch(() => {
|
|
230
|
+
this.logger.info(`Cancelled step run ${action.stepRunId}`);
|
|
231
|
+
});
|
|
232
|
+
future.cancel('Cancelled by worker');
|
|
233
|
+
delete this.futures[stepRunId];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
this.logger.error(`Could not cancel step run: ${e.message}`);
|
|
232
238
|
}
|
|
233
239
|
}
|
|
234
240
|
stop() {
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
const hatchet_client_1 = require("./clients/hatchet-client");
|
|
18
|
+
__exportStar(require("./workflow"), exports);
|
|
19
|
+
__exportStar(require("./step"), exports);
|
|
20
|
+
__exportStar(require("./clients/worker"), exports);
|
|
4
21
|
exports.default = hatchet_client_1.HatchetClient;
|
package/package.json
CHANGED
package/step.d.ts
CHANGED
package/step.js
CHANGED
package/workflow.d.ts
CHANGED
|
@@ -17,15 +17,15 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
|
|
|
17
17
|
export type Steps = z.infer<typeof StepsSchema>;
|
|
18
18
|
export declare const ConcurrencyLimitStrategy: typeof PbConcurrencyLimitStrategy;
|
|
19
19
|
export declare const WorkflowConcurrency: z.ZodObject<{
|
|
20
|
-
|
|
20
|
+
name: z.ZodString;
|
|
21
21
|
maxRuns: z.ZodOptional<z.ZodNumber>;
|
|
22
22
|
limitStrategy: z.ZodOptional<z.ZodNativeEnum<typeof PbConcurrencyLimitStrategy>>;
|
|
23
23
|
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
|
|
24
|
+
name: string;
|
|
25
25
|
maxRuns?: number | undefined;
|
|
26
26
|
limitStrategy?: PbConcurrencyLimitStrategy | undefined;
|
|
27
27
|
}, {
|
|
28
|
-
|
|
28
|
+
name: string;
|
|
29
29
|
maxRuns?: number | undefined;
|
|
30
30
|
limitStrategy?: PbConcurrencyLimitStrategy | undefined;
|
|
31
31
|
}>;
|
package/workflow.js
CHANGED
|
@@ -39,7 +39,7 @@ const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
|
|
|
39
39
|
const StepsSchema = z.array(step_1.CreateStepSchema);
|
|
40
40
|
exports.ConcurrencyLimitStrategy = workflows_1.ConcurrencyLimitStrategy;
|
|
41
41
|
exports.WorkflowConcurrency = z.object({
|
|
42
|
-
|
|
42
|
+
name: z.string(),
|
|
43
43
|
maxRuns: z.number().optional(),
|
|
44
44
|
limitStrategy: z.nativeEnum(exports.ConcurrencyLimitStrategy).optional(),
|
|
45
45
|
});
|