@hatchet-dev/typescript-sdk 0.1.14 → 0.1.15
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/dispatcher/dispatcher-client.d.ts +1 -0
- package/clients/hatchet-client/hatchet-client.d.ts +1 -1
- package/clients/hatchet-client/hatchet-client.js +3 -1
- package/clients/worker/worker.d.ts +2 -0
- package/clients/worker/worker.js +4 -2
- package/package.json +5 -3
- package/protoc/dispatcher/dispatcher.d.ts +2 -0
- package/protoc/dispatcher/dispatcher.js +16 -2
- package/protoc/workflows/workflows.d.ts +1 -0
- package/protoc/workflows/workflows.js +6 -0
- package/step.d.ts +3 -1
- package/step.js +11 -4
|
@@ -28,5 +28,5 @@ export declare class HatchetClient {
|
|
|
28
28
|
static with_host_port(host: string, port: number, config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
|
|
29
29
|
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
|
|
30
30
|
run(workflow: string | Workflow): Promise<Worker>;
|
|
31
|
-
worker(workflow: string | Workflow): Promise<Worker>;
|
|
31
|
+
worker(workflow: string | Workflow, maxRuns?: number): Promise<Worker>;
|
|
32
32
|
}
|
|
@@ -114,6 +114,7 @@ class HatchetClient {
|
|
|
114
114
|
static init(config, options, axiosConfig) {
|
|
115
115
|
return new HatchetClient(config, options, axiosConfig);
|
|
116
116
|
}
|
|
117
|
+
// @deprecated
|
|
117
118
|
run(workflow) {
|
|
118
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
120
|
const worker = yield this.worker(workflow);
|
|
@@ -121,11 +122,12 @@ class HatchetClient {
|
|
|
121
122
|
return worker;
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
|
-
worker(workflow) {
|
|
125
|
+
worker(workflow, maxRuns) {
|
|
125
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
127
|
const name = typeof workflow === 'string' ? workflow : workflow.id;
|
|
127
128
|
const worker = new worker_1.Worker(this, {
|
|
128
129
|
name,
|
|
130
|
+
maxRuns,
|
|
129
131
|
});
|
|
130
132
|
if (typeof workflow !== 'string') {
|
|
131
133
|
yield worker.registerWorkflow(workflow);
|
|
@@ -16,10 +16,12 @@ export declare class Worker {
|
|
|
16
16
|
listener: ActionListener | undefined;
|
|
17
17
|
futures: Record<Action['stepRunId'], HatchetPromise<any>>;
|
|
18
18
|
contexts: Record<Action['stepRunId'], Context<any, any>>;
|
|
19
|
+
maxRuns?: number;
|
|
19
20
|
logger: Logger;
|
|
20
21
|
constructor(client: HatchetClient, options: {
|
|
21
22
|
name: string;
|
|
22
23
|
handleKill?: boolean;
|
|
24
|
+
maxRuns?: number;
|
|
23
25
|
});
|
|
24
26
|
registerWorkflow(workflow: Workflow): Promise<void>;
|
|
25
27
|
registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
|
package/clients/worker/worker.js
CHANGED
|
@@ -35,6 +35,7 @@ class Worker {
|
|
|
35
35
|
this.client = client;
|
|
36
36
|
this.name = options.name;
|
|
37
37
|
this.action_registry = {};
|
|
38
|
+
this.maxRuns = options.maxRuns;
|
|
38
39
|
process.on('SIGTERM', () => this.exitGracefully());
|
|
39
40
|
process.on('SIGINT', () => this.exitGracefully());
|
|
40
41
|
this.killing = false;
|
|
@@ -97,7 +98,7 @@ class Worker {
|
|
|
97
98
|
}
|
|
98
99
|
handleStartStepRun(action) {
|
|
99
100
|
const { actionId } = action;
|
|
100
|
-
const context = new step_1.Context(action
|
|
101
|
+
const context = new step_1.Context(action);
|
|
101
102
|
this.contexts[action.stepRunId] = context;
|
|
102
103
|
const step = this.action_registry[actionId];
|
|
103
104
|
if (!step) {
|
|
@@ -146,7 +147,7 @@ class Worker {
|
|
|
146
147
|
}
|
|
147
148
|
handleStartGroupKeyRun(action) {
|
|
148
149
|
const { actionId } = action;
|
|
149
|
-
const context = new step_1.Context(action
|
|
150
|
+
const context = new step_1.Context(action);
|
|
150
151
|
const key = action.getGroupKeyRunId;
|
|
151
152
|
this.contexts[key] = context;
|
|
152
153
|
this.logger.debug(`Starting group key run ${key}`);
|
|
@@ -276,6 +277,7 @@ class Worker {
|
|
|
276
277
|
workerName: this.name,
|
|
277
278
|
services: ['default'],
|
|
278
279
|
actions: Object.keys(this.action_registry),
|
|
280
|
+
maxRuns: this.maxRuns,
|
|
279
281
|
});
|
|
280
282
|
const generator = this.listener.actions();
|
|
281
283
|
this.logger.info(`Worker ${this.name} listening for actions`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"worker:simple": "npm run exec -- ./examples/simple-worker.ts",
|
|
32
32
|
"manual:trigger": "npm run exec -- ./examples/manual-trigger.ts",
|
|
33
33
|
"worker:dag": "npm run exec -- ./examples/dag-worker.ts",
|
|
34
|
-
"worker:concurrency": "npm run exec -- ./examples/concurrency/concurrency-worker.ts",
|
|
35
|
-
"event:concurrency": "npm run exec -- ./examples/concurrency/concurrency-event.ts",
|
|
34
|
+
"worker:concurrency": "npm run exec -- ./examples/concurrency/cancel-in-progress/concurrency-worker.ts",
|
|
35
|
+
"event:concurrency": "npm run exec -- ./examples/concurrency/cancel-in-progress/concurrency-event.ts",
|
|
36
|
+
"worker:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-worker.ts",
|
|
37
|
+
"event:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-event.ts",
|
|
36
38
|
"worker:retries": "npm run exec -- ./examples/retries-worker.ts",
|
|
37
39
|
"api": "npm run exec -- ./examples/api.ts",
|
|
38
40
|
"prepublish": "cp package.json dist/package.json;",
|
|
@@ -53,6 +53,8 @@ export interface WorkerRegisterRequest {
|
|
|
53
53
|
actions: string[];
|
|
54
54
|
/** (optional) the services for this worker */
|
|
55
55
|
services: string[];
|
|
56
|
+
/** (optional) the max number of runs this worker can handle */
|
|
57
|
+
maxRuns?: number | undefined;
|
|
56
58
|
}
|
|
57
59
|
export interface WorkerRegisterResponse {
|
|
58
60
|
/** the tenant id */
|
|
@@ -253,7 +253,7 @@ function resourceEventTypeToJSON(object) {
|
|
|
253
253
|
}
|
|
254
254
|
exports.resourceEventTypeToJSON = resourceEventTypeToJSON;
|
|
255
255
|
function createBaseWorkerRegisterRequest() {
|
|
256
|
-
return { workerName: "", actions: [], services: [] };
|
|
256
|
+
return { workerName: "", actions: [], services: [], maxRuns: undefined };
|
|
257
257
|
}
|
|
258
258
|
exports.WorkerRegisterRequest = {
|
|
259
259
|
encode(message, writer = _m0.Writer.create()) {
|
|
@@ -266,6 +266,9 @@ exports.WorkerRegisterRequest = {
|
|
|
266
266
|
for (const v of message.services) {
|
|
267
267
|
writer.uint32(26).string(v);
|
|
268
268
|
}
|
|
269
|
+
if (message.maxRuns !== undefined) {
|
|
270
|
+
writer.uint32(32).int32(message.maxRuns);
|
|
271
|
+
}
|
|
269
272
|
return writer;
|
|
270
273
|
},
|
|
271
274
|
decode(input, length) {
|
|
@@ -293,6 +296,12 @@ exports.WorkerRegisterRequest = {
|
|
|
293
296
|
}
|
|
294
297
|
message.services.push(reader.string());
|
|
295
298
|
continue;
|
|
299
|
+
case 4:
|
|
300
|
+
if (tag !== 32) {
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
message.maxRuns = reader.int32();
|
|
304
|
+
continue;
|
|
296
305
|
}
|
|
297
306
|
if ((tag & 7) === 4 || tag === 0) {
|
|
298
307
|
break;
|
|
@@ -306,6 +315,7 @@ exports.WorkerRegisterRequest = {
|
|
|
306
315
|
workerName: isSet(object.workerName) ? globalThis.String(object.workerName) : "",
|
|
307
316
|
actions: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.actions) ? object.actions.map((e) => globalThis.String(e)) : [],
|
|
308
317
|
services: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.services) ? object.services.map((e) => globalThis.String(e)) : [],
|
|
318
|
+
maxRuns: isSet(object.maxRuns) ? globalThis.Number(object.maxRuns) : undefined,
|
|
309
319
|
};
|
|
310
320
|
},
|
|
311
321
|
toJSON(message) {
|
|
@@ -320,17 +330,21 @@ exports.WorkerRegisterRequest = {
|
|
|
320
330
|
if ((_b = message.services) === null || _b === void 0 ? void 0 : _b.length) {
|
|
321
331
|
obj.services = message.services;
|
|
322
332
|
}
|
|
333
|
+
if (message.maxRuns !== undefined) {
|
|
334
|
+
obj.maxRuns = Math.round(message.maxRuns);
|
|
335
|
+
}
|
|
323
336
|
return obj;
|
|
324
337
|
},
|
|
325
338
|
create(base) {
|
|
326
339
|
return exports.WorkerRegisterRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
327
340
|
},
|
|
328
341
|
fromPartial(object) {
|
|
329
|
-
var _a, _b, _c;
|
|
342
|
+
var _a, _b, _c, _d;
|
|
330
343
|
const message = createBaseWorkerRegisterRequest();
|
|
331
344
|
message.workerName = (_a = object.workerName) !== null && _a !== void 0 ? _a : "";
|
|
332
345
|
message.actions = ((_b = object.actions) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
|
|
333
346
|
message.services = ((_c = object.services) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
|
|
347
|
+
message.maxRuns = (_d = object.maxRuns) !== null && _d !== void 0 ? _d : undefined;
|
|
334
348
|
return message;
|
|
335
349
|
},
|
|
336
350
|
};
|
|
@@ -33,6 +33,7 @@ var ConcurrencyLimitStrategy;
|
|
|
33
33
|
ConcurrencyLimitStrategy[ConcurrencyLimitStrategy["CANCEL_IN_PROGRESS"] = 0] = "CANCEL_IN_PROGRESS";
|
|
34
34
|
ConcurrencyLimitStrategy[ConcurrencyLimitStrategy["DROP_NEWEST"] = 1] = "DROP_NEWEST";
|
|
35
35
|
ConcurrencyLimitStrategy[ConcurrencyLimitStrategy["QUEUE_NEWEST"] = 2] = "QUEUE_NEWEST";
|
|
36
|
+
ConcurrencyLimitStrategy[ConcurrencyLimitStrategy["GROUP_ROUND_ROBIN"] = 3] = "GROUP_ROUND_ROBIN";
|
|
36
37
|
ConcurrencyLimitStrategy[ConcurrencyLimitStrategy["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
37
38
|
})(ConcurrencyLimitStrategy || (exports.ConcurrencyLimitStrategy = ConcurrencyLimitStrategy = {}));
|
|
38
39
|
function concurrencyLimitStrategyFromJSON(object) {
|
|
@@ -46,6 +47,9 @@ function concurrencyLimitStrategyFromJSON(object) {
|
|
|
46
47
|
case 2:
|
|
47
48
|
case "QUEUE_NEWEST":
|
|
48
49
|
return ConcurrencyLimitStrategy.QUEUE_NEWEST;
|
|
50
|
+
case 3:
|
|
51
|
+
case "GROUP_ROUND_ROBIN":
|
|
52
|
+
return ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN;
|
|
49
53
|
case -1:
|
|
50
54
|
case "UNRECOGNIZED":
|
|
51
55
|
default:
|
|
@@ -61,6 +65,8 @@ function concurrencyLimitStrategyToJSON(object) {
|
|
|
61
65
|
return "DROP_NEWEST";
|
|
62
66
|
case ConcurrencyLimitStrategy.QUEUE_NEWEST:
|
|
63
67
|
return "QUEUE_NEWEST";
|
|
68
|
+
case ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN:
|
|
69
|
+
return "GROUP_ROUND_ROBIN";
|
|
64
70
|
case ConcurrencyLimitStrategy.UNRECOGNIZED:
|
|
65
71
|
default:
|
|
66
72
|
return "UNRECOGNIZED";
|
package/step.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
import { Action } from './clients/dispatcher/action-listener';
|
|
2
3
|
export declare const CreateStepSchema: z.ZodObject<{
|
|
3
4
|
name: z.ZodString;
|
|
4
5
|
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -26,8 +27,9 @@ interface ContextData<T, K> {
|
|
|
26
27
|
}
|
|
27
28
|
export declare class Context<T, K> {
|
|
28
29
|
data: ContextData<T, K>;
|
|
30
|
+
input: T;
|
|
29
31
|
controller: AbortController;
|
|
30
|
-
constructor(
|
|
32
|
+
constructor(action: Action);
|
|
31
33
|
stepOutput(step: string): string;
|
|
32
34
|
triggeredByEvent(): boolean;
|
|
33
35
|
workflowInput(): T;
|
package/step.js
CHANGED
|
@@ -37,10 +37,18 @@ exports.CreateStepSchema = z.object({
|
|
|
37
37
|
retries: z.number().optional(),
|
|
38
38
|
});
|
|
39
39
|
class Context {
|
|
40
|
-
constructor(
|
|
40
|
+
constructor(action) {
|
|
41
41
|
this.controller = new AbortController();
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
const data = JSON.parse(JSON.parse(action.actionPayload));
|
|
44
|
+
this.data = data;
|
|
45
|
+
// if this is a getGroupKeyRunId, the data is the workflow input
|
|
46
|
+
if (action.getGroupKeyRunId !== '') {
|
|
47
|
+
this.input = data;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.input = data.input;
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
53
|
catch (e) {
|
|
46
54
|
throw new hatchet_error_1.default(`Could not parse payload: ${e.message}`);
|
|
@@ -60,8 +68,7 @@ class Context {
|
|
|
60
68
|
return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.triggered_by) === 'event';
|
|
61
69
|
}
|
|
62
70
|
workflowInput() {
|
|
63
|
-
|
|
64
|
-
return (_a = this.data) === null || _a === void 0 ? void 0 : _a.input;
|
|
71
|
+
return this.input;
|
|
65
72
|
}
|
|
66
73
|
userData() {
|
|
67
74
|
var _a;
|