@hatchet-dev/typescript-sdk 0.1.16 → 0.1.19
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 +85 -84
- package/package.json +2 -1
- package/protoc/workflows/workflows.d.ts +2 -0
- package/protoc/workflows/workflows.js +16 -1
- package/workflow.d.ts +3 -0
- package/workflow.js +1 -0
|
@@ -7,7 +7,6 @@ import { Logger } from '../../util/logger';
|
|
|
7
7
|
import { Context, StepRunFunction } from '../../step';
|
|
8
8
|
export type ActionRegistry = Record<Action['actionId'], Function>;
|
|
9
9
|
export declare class Worker {
|
|
10
|
-
serviceName: string;
|
|
11
10
|
client: HatchetClient;
|
|
12
11
|
name: string;
|
|
13
12
|
killing: boolean;
|
package/clients/worker/worker.js
CHANGED
|
@@ -29,7 +29,6 @@ const logger_1 = require("../../util/logger");
|
|
|
29
29
|
const step_1 = require("../../step");
|
|
30
30
|
class Worker {
|
|
31
31
|
constructor(client, options) {
|
|
32
|
-
this.serviceName = 'default';
|
|
33
32
|
this.futures = {};
|
|
34
33
|
this.contexts = {};
|
|
35
34
|
this.client = client;
|
|
@@ -48,7 +47,7 @@ class Worker {
|
|
|
48
47
|
try {
|
|
49
48
|
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
50
49
|
? {
|
|
51
|
-
action: `${
|
|
50
|
+
action: `${workflow.id}:${workflow.concurrency.name}`,
|
|
52
51
|
maxRuns: workflow.concurrency.maxRuns || 1,
|
|
53
52
|
limitStrategy: workflow.concurrency.limitStrategy || workflows_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
|
54
53
|
}
|
|
@@ -61,6 +60,7 @@ class Worker {
|
|
|
61
60
|
cronTriggers: workflow.on.cron ? [workflow.on.cron] : [],
|
|
62
61
|
scheduledTriggers: [],
|
|
63
62
|
concurrency,
|
|
63
|
+
scheduleTimeout: workflow.scheduleTimeout,
|
|
64
64
|
jobs: [
|
|
65
65
|
{
|
|
66
66
|
name: workflow.id,
|
|
@@ -70,7 +70,7 @@ class Worker {
|
|
|
70
70
|
var _a;
|
|
71
71
|
return ({
|
|
72
72
|
readableId: step.name,
|
|
73
|
-
action: `${
|
|
73
|
+
action: `${workflow.id}:${step.name}`,
|
|
74
74
|
timeout: step.timeout || '60s',
|
|
75
75
|
inputs: '{}',
|
|
76
76
|
parents: (_a = step.parents) !== null && _a !== void 0 ? _a : [],
|
|
@@ -85,12 +85,13 @@ class Worker {
|
|
|
85
85
|
catch (e) {
|
|
86
86
|
throw new hatchet_error_1.default(`Could not register workflow: ${e.message}`);
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
acc[`${
|
|
88
|
+
const newActions = workflow.steps.reduce((acc, step) => {
|
|
89
|
+
acc[`${workflow.id}:${step.name}`] = step.run;
|
|
90
90
|
return acc;
|
|
91
91
|
}, {});
|
|
92
|
+
this.action_registry = Object.assign(Object.assign({}, this.action_registry), newActions);
|
|
92
93
|
this.action_registry = ((_b = workflow.concurrency) === null || _b === void 0 ? void 0 : _b.name)
|
|
93
|
-
? Object.assign(Object.assign({}, this.action_registry), { [`${
|
|
94
|
+
? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
registerAction(actionId, action) {
|
|
@@ -98,45 +99,45 @@ class Worker {
|
|
|
98
99
|
}
|
|
99
100
|
handleStartStepRun(action) {
|
|
100
101
|
const { actionId } = action;
|
|
101
|
-
const context = new step_1.Context(action);
|
|
102
|
-
this.contexts[action.stepRunId] = context;
|
|
103
|
-
const step = this.action_registry[actionId];
|
|
104
|
-
if (!step) {
|
|
105
|
-
this.logger.error(`Could not find step '${actionId}'`);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
return step(context);
|
|
110
|
-
});
|
|
111
|
-
const success = (result) => {
|
|
112
|
-
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
113
|
-
try {
|
|
114
|
-
// Send the action event to the dispatcher
|
|
115
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result);
|
|
116
|
-
this.client.dispatcher.sendStepActionEvent(event);
|
|
117
|
-
// delete the run from the futures
|
|
118
|
-
delete this.futures[action.stepRunId];
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const failure = (error) => {
|
|
125
|
-
this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
|
|
126
|
-
try {
|
|
127
|
-
// Send the action event to the dispatcher
|
|
128
|
-
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, error);
|
|
129
|
-
this.client.dispatcher.sendStepActionEvent(event);
|
|
130
|
-
// delete the run from the futures
|
|
131
|
-
delete this.futures[action.stepRunId];
|
|
132
|
-
}
|
|
133
|
-
catch (e) {
|
|
134
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
138
|
-
this.futures[action.stepRunId] = future;
|
|
139
102
|
try {
|
|
103
|
+
const context = new step_1.Context(action);
|
|
104
|
+
this.contexts[action.stepRunId] = context;
|
|
105
|
+
const step = this.action_registry[actionId];
|
|
106
|
+
if (!step) {
|
|
107
|
+
this.logger.error(`Could not find step '${actionId}'`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return step(context);
|
|
112
|
+
});
|
|
113
|
+
const success = (result) => {
|
|
114
|
+
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
115
|
+
try {
|
|
116
|
+
// Send the action event to the dispatcher
|
|
117
|
+
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result);
|
|
118
|
+
this.client.dispatcher.sendStepActionEvent(event);
|
|
119
|
+
// delete the run from the futures
|
|
120
|
+
delete this.futures[action.stepRunId];
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const failure = (error) => {
|
|
127
|
+
this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
|
|
128
|
+
try {
|
|
129
|
+
// Send the action event to the dispatcher
|
|
130
|
+
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, error);
|
|
131
|
+
this.client.dispatcher.sendStepActionEvent(event);
|
|
132
|
+
// delete the run from the futures
|
|
133
|
+
delete this.futures[action.stepRunId];
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
140
|
+
this.futures[action.stepRunId] = future;
|
|
140
141
|
// Send the action event to the dispatcher
|
|
141
142
|
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
|
|
142
143
|
this.client.dispatcher.sendStepActionEvent(event);
|
|
@@ -147,47 +148,47 @@ class Worker {
|
|
|
147
148
|
}
|
|
148
149
|
handleStartGroupKeyRun(action) {
|
|
149
150
|
const { actionId } = action;
|
|
150
|
-
const context = new step_1.Context(action);
|
|
151
|
-
const key = action.getGroupKeyRunId;
|
|
152
|
-
this.contexts[key] = context;
|
|
153
|
-
this.logger.debug(`Starting group key run ${key}`);
|
|
154
|
-
const step = this.action_registry[actionId];
|
|
155
|
-
if (!step) {
|
|
156
|
-
this.logger.error(`Could not find step '${actionId}'`);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
return step(context);
|
|
161
|
-
});
|
|
162
|
-
const success = (result) => {
|
|
163
|
-
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
164
|
-
try {
|
|
165
|
-
// Send the action event to the dispatcher
|
|
166
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
167
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event);
|
|
168
|
-
// delete the run from the futures
|
|
169
|
-
delete this.futures[key];
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const failure = (error) => {
|
|
176
|
-
this.logger.error(`Step run ${key} failed: ${error.message}`);
|
|
177
|
-
try {
|
|
178
|
-
// Send the action event to the dispatcher
|
|
179
|
-
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
180
|
-
this.client.dispatcher.sendGroupKeyActionEvent(event);
|
|
181
|
-
// delete the run from the futures
|
|
182
|
-
delete this.futures[key];
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
this.logger.error(`Could not send action event: ${e.message}`);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
189
|
-
this.futures[action.getGroupKeyRunId] = future;
|
|
190
151
|
try {
|
|
152
|
+
const context = new step_1.Context(action);
|
|
153
|
+
const key = action.getGroupKeyRunId;
|
|
154
|
+
this.contexts[key] = context;
|
|
155
|
+
this.logger.debug(`Starting group key run ${key}`);
|
|
156
|
+
const step = this.action_registry[actionId];
|
|
157
|
+
if (!step) {
|
|
158
|
+
this.logger.error(`Could not find step '${actionId}'`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
return step(context);
|
|
163
|
+
});
|
|
164
|
+
const success = (result) => {
|
|
165
|
+
this.logger.info(`Step run ${action.stepRunId} succeeded`);
|
|
166
|
+
try {
|
|
167
|
+
// Send the action event to the dispatcher
|
|
168
|
+
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
169
|
+
this.client.dispatcher.sendGroupKeyActionEvent(event);
|
|
170
|
+
// delete the run from the futures
|
|
171
|
+
delete this.futures[key];
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const failure = (error) => {
|
|
178
|
+
this.logger.error(`Step run ${key} failed: ${error.message}`);
|
|
179
|
+
try {
|
|
180
|
+
// Send the action event to the dispatcher
|
|
181
|
+
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
182
|
+
this.client.dispatcher.sendGroupKeyActionEvent(event);
|
|
183
|
+
// delete the run from the futures
|
|
184
|
+
delete this.futures[key];
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
this.logger.error(`Could not send action event: ${e.message}`);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const future = new hatchet_promise_1.default(run().then(success).catch(failure));
|
|
191
|
+
this.futures[action.getGroupKeyRunId] = future;
|
|
191
192
|
// Send the action event to the dispatcher
|
|
192
193
|
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
|
|
193
194
|
this.client.dispatcher.sendStepActionEvent(event);
|
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.19",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"worker:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-worker.ts",
|
|
37
37
|
"event:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-event.ts",
|
|
38
38
|
"worker:retries": "npm run exec -- ./examples/retries-worker.ts",
|
|
39
|
+
"worker:multi-workflow": "npm run exec -- ./examples/multi-workflow.ts",
|
|
39
40
|
"api": "npm run exec -- ./examples/api.ts",
|
|
40
41
|
"prepublish": "cp package.json dist/package.json;",
|
|
41
42
|
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
|
|
@@ -31,6 +31,8 @@ export interface CreateWorkflowVersionOpts {
|
|
|
31
31
|
jobs: CreateWorkflowJobOpts[];
|
|
32
32
|
/** (optional) the workflow concurrency options */
|
|
33
33
|
concurrency: WorkflowConcurrencyOpts | undefined;
|
|
34
|
+
/** (optional) the timeout for the schedule */
|
|
35
|
+
scheduleTimeout?: string | undefined;
|
|
34
36
|
}
|
|
35
37
|
export interface WorkflowConcurrencyOpts {
|
|
36
38
|
/** (required) the action id for getting the concurrency group */
|
|
@@ -135,6 +135,7 @@ function createBaseCreateWorkflowVersionOpts() {
|
|
|
135
135
|
scheduledTriggers: [],
|
|
136
136
|
jobs: [],
|
|
137
137
|
concurrency: undefined,
|
|
138
|
+
scheduleTimeout: undefined,
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
exports.CreateWorkflowVersionOpts = {
|
|
@@ -163,6 +164,9 @@ exports.CreateWorkflowVersionOpts = {
|
|
|
163
164
|
if (message.concurrency !== undefined) {
|
|
164
165
|
exports.WorkflowConcurrencyOpts.encode(message.concurrency, writer.uint32(66).fork()).ldelim();
|
|
165
166
|
}
|
|
167
|
+
if (message.scheduleTimeout !== undefined) {
|
|
168
|
+
writer.uint32(74).string(message.scheduleTimeout);
|
|
169
|
+
}
|
|
166
170
|
return writer;
|
|
167
171
|
},
|
|
168
172
|
decode(input, length) {
|
|
@@ -220,6 +224,12 @@ exports.CreateWorkflowVersionOpts = {
|
|
|
220
224
|
}
|
|
221
225
|
message.concurrency = exports.WorkflowConcurrencyOpts.decode(reader, reader.uint32());
|
|
222
226
|
continue;
|
|
227
|
+
case 9:
|
|
228
|
+
if (tag !== 74) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
message.scheduleTimeout = reader.string();
|
|
232
|
+
continue;
|
|
223
233
|
}
|
|
224
234
|
if ((tag & 7) === 4 || tag === 0) {
|
|
225
235
|
break;
|
|
@@ -246,6 +256,7 @@ exports.CreateWorkflowVersionOpts = {
|
|
|
246
256
|
? object.jobs.map((e) => exports.CreateWorkflowJobOpts.fromJSON(e))
|
|
247
257
|
: [],
|
|
248
258
|
concurrency: isSet(object.concurrency) ? exports.WorkflowConcurrencyOpts.fromJSON(object.concurrency) : undefined,
|
|
259
|
+
scheduleTimeout: isSet(object.scheduleTimeout) ? globalThis.String(object.scheduleTimeout) : undefined,
|
|
249
260
|
};
|
|
250
261
|
},
|
|
251
262
|
toJSON(message) {
|
|
@@ -275,13 +286,16 @@ exports.CreateWorkflowVersionOpts = {
|
|
|
275
286
|
if (message.concurrency !== undefined) {
|
|
276
287
|
obj.concurrency = exports.WorkflowConcurrencyOpts.toJSON(message.concurrency);
|
|
277
288
|
}
|
|
289
|
+
if (message.scheduleTimeout !== undefined) {
|
|
290
|
+
obj.scheduleTimeout = message.scheduleTimeout;
|
|
291
|
+
}
|
|
278
292
|
return obj;
|
|
279
293
|
},
|
|
280
294
|
create(base) {
|
|
281
295
|
return exports.CreateWorkflowVersionOpts.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
282
296
|
},
|
|
283
297
|
fromPartial(object) {
|
|
284
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
298
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
285
299
|
const message = createBaseCreateWorkflowVersionOpts();
|
|
286
300
|
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : "";
|
|
287
301
|
message.description = (_b = object.description) !== null && _b !== void 0 ? _b : "";
|
|
@@ -293,6 +307,7 @@ exports.CreateWorkflowVersionOpts = {
|
|
|
293
307
|
message.concurrency = (object.concurrency !== undefined && object.concurrency !== null)
|
|
294
308
|
? exports.WorkflowConcurrencyOpts.fromPartial(object.concurrency)
|
|
295
309
|
: undefined;
|
|
310
|
+
message.scheduleTimeout = (_h = object.scheduleTimeout) !== null && _h !== void 0 ? _h : undefined;
|
|
296
311
|
return message;
|
|
297
312
|
},
|
|
298
313
|
};
|
package/workflow.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
37
37
|
id: z.ZodString;
|
|
38
38
|
description: z.ZodString;
|
|
39
39
|
version: z.ZodOptional<z.ZodString>;
|
|
40
|
+
scheduleTimeout: z.ZodOptional<z.ZodString>;
|
|
40
41
|
timeout: z.ZodOptional<z.ZodString>;
|
|
41
42
|
on: z.ZodUnion<[z.ZodObject<{
|
|
42
43
|
cron: z.ZodString;
|
|
@@ -90,6 +91,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
90
91
|
cron?: undefined;
|
|
91
92
|
};
|
|
92
93
|
version?: string | undefined;
|
|
94
|
+
scheduleTimeout?: string | undefined;
|
|
93
95
|
timeout?: string | undefined;
|
|
94
96
|
}, {
|
|
95
97
|
description: string;
|
|
@@ -108,6 +110,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
108
110
|
cron?: undefined;
|
|
109
111
|
};
|
|
110
112
|
version?: string | undefined;
|
|
113
|
+
scheduleTimeout?: string | undefined;
|
|
111
114
|
timeout?: string | undefined;
|
|
112
115
|
}>;
|
|
113
116
|
export interface Workflow extends z.infer<typeof CreateWorkflowSchema> {
|
package/workflow.js
CHANGED
|
@@ -48,6 +48,7 @@ exports.CreateWorkflowSchema = z.object({
|
|
|
48
48
|
id: z.string(),
|
|
49
49
|
description: z.string(),
|
|
50
50
|
version: z.string().optional(),
|
|
51
|
+
scheduleTimeout: z.string().optional(),
|
|
51
52
|
timeout: exports.HatchetTimeoutSchema.optional(),
|
|
52
53
|
on: OnConfigSchema,
|
|
53
54
|
steps: StepsSchema,
|