@hatchet-dev/typescript-sdk 1.12.0 → 1.12.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/dispatcher/dispatcher-client.d.ts +14 -1
- package/clients/dispatcher/dispatcher-client.js +25 -2
- package/clients/rest/generated/Api.d.ts +9 -1
- package/clients/rest/generated/data-contracts.d.ts +43 -7
- package/clients/rest/generated/data-contracts.js +13 -2
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +46 -1
- package/protoc/dispatcher/dispatcher.js +214 -2
- package/protoc/v1/workflows.d.ts +11 -0
- package/protoc/v1/workflows.js +122 -2
- package/step.d.ts +6 -0
- package/step.js +9 -1
- package/v1/client/client.js +1 -1
- package/v1/client/worker/context.d.ts +6 -0
- package/v1/client/worker/context.js +8 -0
- package/v1/client/worker/deprecated/deprecation.d.ts +44 -0
- package/v1/client/worker/deprecated/deprecation.js +95 -0
- package/v1/client/worker/deprecated/index.d.ts +4 -0
- package/v1/client/worker/deprecated/index.js +15 -0
- package/v1/client/worker/deprecated/legacy-registration.d.ts +18 -0
- package/v1/client/worker/deprecated/legacy-registration.js +35 -0
- package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +15 -0
- package/v1/client/worker/deprecated/legacy-v1-worker.js +39 -0
- package/v1/client/worker/deprecated/legacy-worker.d.ts +41 -0
- package/v1/client/worker/deprecated/legacy-worker.js +148 -0
- package/v1/client/worker/slot-utils.d.ts +21 -0
- package/v1/client/worker/slot-utils.js +73 -0
- package/v1/client/worker/worker-internal.d.ts +14 -3
- package/v1/client/worker/worker-internal.js +29 -12
- package/v1/client/worker/worker.d.ts +12 -15
- package/v1/client/worker/worker.js +45 -49
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/slot-types.d.ts +5 -0
- package/v1/slot-types.js +9 -0
- package/v1/task.d.ts +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +2 -2
|
@@ -5,23 +5,16 @@ import { WebhookWorkerCreateRequest } from '../../../clients/rest/generated/data
|
|
|
5
5
|
import { BaseWorkflowDeclaration } from '../../declaration';
|
|
6
6
|
import { HatchetClient } from '../..';
|
|
7
7
|
import { V1Worker } from './worker-internal';
|
|
8
|
+
import { type WorkerSlotOptions } from './slot-utils';
|
|
8
9
|
/**
|
|
9
10
|
* Options for creating a new hatchet worker
|
|
10
11
|
* @interface CreateWorkerOpts
|
|
11
12
|
*/
|
|
12
|
-
export interface CreateWorkerOpts {
|
|
13
|
-
/** (optional) Maximum number of concurrent runs on this worker, defaults to 100 */
|
|
14
|
-
slots?: number;
|
|
15
|
-
/** (optional) Array of workflows to register */
|
|
16
|
-
workflows?: BaseWorkflowDeclaration<any, any>[] | V0Workflow[];
|
|
13
|
+
export interface CreateWorkerOpts extends WorkerSlotOptions {
|
|
17
14
|
/** (optional) Worker labels for affinity-based assignment */
|
|
18
15
|
labels?: WorkerLabels;
|
|
19
16
|
/** (optional) Whether to handle kill signals */
|
|
20
17
|
handleKill?: boolean;
|
|
21
|
-
/** @deprecated Use slots instead */
|
|
22
|
-
maxRuns?: number;
|
|
23
|
-
/** (optional) Maximum number of concurrent runs on the durable worker, defaults to 1,000 */
|
|
24
|
-
durableSlots?: number;
|
|
25
18
|
}
|
|
26
19
|
/**
|
|
27
20
|
* HatchetWorker class for workflow execution runtime
|
|
@@ -32,8 +25,11 @@ export declare class Worker {
|
|
|
32
25
|
_v1: HatchetClient;
|
|
33
26
|
_v0: LegacyHatchetClient;
|
|
34
27
|
/** Internal reference to the underlying V0 worker implementation */
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
_internal: V1Worker;
|
|
29
|
+
/** Set when connected to a legacy engine that needs dual-worker architecture */
|
|
30
|
+
private _legacyWorker;
|
|
31
|
+
/** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
|
|
32
|
+
private _registeredWorkflows;
|
|
37
33
|
/**
|
|
38
34
|
* Creates a new HatchetWorker instance
|
|
39
35
|
* @param nonDurable - The V0 worker implementation
|
|
@@ -63,12 +59,12 @@ export declare class Worker {
|
|
|
63
59
|
* Starts the worker
|
|
64
60
|
* @returns Promise that resolves when the worker is stopped or killed
|
|
65
61
|
*/
|
|
66
|
-
start(): Promise<void
|
|
62
|
+
start(): Promise<void>;
|
|
67
63
|
/**
|
|
68
64
|
* Stops the worker
|
|
69
65
|
* @returns Promise that resolves when the worker stops
|
|
70
66
|
*/
|
|
71
|
-
stop(): Promise<void
|
|
67
|
+
stop(): Promise<void>;
|
|
72
68
|
/**
|
|
73
69
|
* Updates or inserts worker labels
|
|
74
70
|
* @param labels - Worker labels to update
|
|
@@ -87,6 +83,7 @@ export declare class Worker {
|
|
|
87
83
|
*/
|
|
88
84
|
registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
|
|
89
85
|
isPaused(): Promise<boolean>;
|
|
90
|
-
pause(): Promise<
|
|
91
|
-
unpause(): Promise<
|
|
86
|
+
pause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
|
|
87
|
+
unpause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
|
|
92
88
|
}
|
|
89
|
+
export { testingExports as __testing } from './slot-utils';
|
|
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Worker = void 0;
|
|
12
|
+
exports.__testing = exports.Worker = void 0;
|
|
13
13
|
const declaration_1 = require("../../declaration");
|
|
14
14
|
const worker_internal_1 = require("./worker-internal");
|
|
15
|
-
const
|
|
15
|
+
const slot_utils_1 = require("./slot-utils");
|
|
16
|
+
const deprecated_1 = require("./deprecated");
|
|
16
17
|
/**
|
|
17
18
|
* HatchetWorker class for workflow execution runtime
|
|
18
19
|
*/
|
|
@@ -22,9 +23,11 @@ class Worker {
|
|
|
22
23
|
* @param nonDurable - The V0 worker implementation
|
|
23
24
|
*/
|
|
24
25
|
constructor(v1, v0, nonDurable, config, name) {
|
|
26
|
+
/** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
|
|
27
|
+
this._registeredWorkflows = [];
|
|
25
28
|
this._v1 = v1;
|
|
26
29
|
this._v0 = v0;
|
|
27
|
-
this.
|
|
30
|
+
this._internal = nonDurable;
|
|
28
31
|
this.config = config;
|
|
29
32
|
this.name = name;
|
|
30
33
|
}
|
|
@@ -36,7 +39,8 @@ class Worker {
|
|
|
36
39
|
*/
|
|
37
40
|
static create(v1, v0, name, options) {
|
|
38
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const
|
|
42
|
+
const resolvedOptions = (0, slot_utils_1.resolveWorkerOptions)(options);
|
|
43
|
+
const opts = Object.assign({ name }, resolvedOptions);
|
|
40
44
|
const internalWorker = new worker_internal_1.V1Worker(v1, opts);
|
|
41
45
|
const worker = new Worker(v1, v0, internalWorker, options, name);
|
|
42
46
|
yield worker.registerWorkflows(options.workflows);
|
|
@@ -51,21 +55,17 @@ class Worker {
|
|
|
51
55
|
registerWorkflows(workflows) {
|
|
52
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
57
|
for (const wf of workflows || []) {
|
|
58
|
+
this._registeredWorkflows.push(wf);
|
|
54
59
|
if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
|
|
55
60
|
// TODO check if tenant is V1
|
|
56
|
-
yield this.
|
|
61
|
+
yield this._internal.registerWorkflowV1(wf);
|
|
57
62
|
if (wf.definition._durableTasks.length > 0) {
|
|
58
|
-
|
|
59
|
-
const opts = Object.assign(Object.assign({ name: `${this.name}-durable` }, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS });
|
|
60
|
-
this.durable = new worker_internal_1.V1Worker(this._v1, opts);
|
|
61
|
-
yield this.durable.registerWorkflowV1(wf, true);
|
|
62
|
-
}
|
|
63
|
-
this.durable.registerDurableActionsV1(wf.definition);
|
|
63
|
+
this._internal.registerDurableActionsV1(wf.definition);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
67
|
// fallback to v0 client for backwards compatibility
|
|
68
|
-
yield this.
|
|
68
|
+
yield this._internal.registerWorkflow(wf);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
});
|
|
@@ -84,22 +84,29 @@ class Worker {
|
|
|
84
84
|
* @returns Promise that resolves when the worker is stopped or killed
|
|
85
85
|
*/
|
|
86
86
|
start() {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
// Check engine version and fall back to legacy dual-worker mode if needed
|
|
89
|
+
if (yield (0, deprecated_1.isLegacyEngine)(this._v1)) {
|
|
90
|
+
// Include workflows registered after construction (via registerWorkflow/registerWorkflows)
|
|
91
|
+
// so the legacy worker picks them up.
|
|
92
|
+
const legacyConfig = Object.assign(Object.assign({}, this.config), { workflows: this._registeredWorkflows.length
|
|
93
|
+
? this._registeredWorkflows
|
|
94
|
+
: this.config.workflows });
|
|
95
|
+
this._legacyWorker = yield deprecated_1.LegacyDualWorker.create(this._v1, this.name, legacyConfig);
|
|
96
|
+
return this._legacyWorker.start();
|
|
97
|
+
}
|
|
98
|
+
return this._internal.start();
|
|
99
|
+
});
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
102
|
* Stops the worker
|
|
95
103
|
* @returns Promise that resolves when the worker stops
|
|
96
104
|
*/
|
|
97
105
|
stop() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
workers.push(this.durable);
|
|
106
|
+
if (this._legacyWorker) {
|
|
107
|
+
return this._legacyWorker.stop();
|
|
101
108
|
}
|
|
102
|
-
return
|
|
109
|
+
return this._internal.stop();
|
|
103
110
|
}
|
|
104
111
|
/**
|
|
105
112
|
* Updates or inserts worker labels
|
|
@@ -107,14 +114,14 @@ class Worker {
|
|
|
107
114
|
* @returns Promise that resolves when labels are updated
|
|
108
115
|
*/
|
|
109
116
|
upsertLabels(labels) {
|
|
110
|
-
return this.
|
|
117
|
+
return this._internal.upsertLabels(labels);
|
|
111
118
|
}
|
|
112
119
|
/**
|
|
113
120
|
* Get the labels for the worker
|
|
114
121
|
* @returns The labels for the worker
|
|
115
122
|
*/
|
|
116
123
|
getLabels() {
|
|
117
|
-
return this.
|
|
124
|
+
return this._internal.labels;
|
|
118
125
|
}
|
|
119
126
|
/**
|
|
120
127
|
* Register a webhook with the worker
|
|
@@ -122,44 +129,33 @@ class Worker {
|
|
|
122
129
|
* @returns A promise that resolves when the webhook is registered
|
|
123
130
|
*/
|
|
124
131
|
registerWebhook(webhook) {
|
|
125
|
-
return this.
|
|
132
|
+
return this._internal.registerWebhook(webhook);
|
|
126
133
|
}
|
|
127
134
|
isPaused() {
|
|
128
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
var _a
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
promises.push(this._v1.workers.isPaused(this.nonDurable.workerId));
|
|
136
|
+
var _a;
|
|
137
|
+
if (!((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)) {
|
|
138
|
+
return false;
|
|
133
139
|
}
|
|
134
|
-
|
|
135
|
-
promises.push(this._v1.workers.isPaused(this.durable.workerId));
|
|
136
|
-
}
|
|
137
|
-
const res = yield Promise.all(promises);
|
|
138
|
-
return !res.includes(false);
|
|
140
|
+
return this._v1.workers.isPaused(this._internal.workerId);
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
// TODO docstrings
|
|
142
144
|
pause() {
|
|
143
|
-
var _a
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
promises.push(this._v1.workers.pause(this.nonDurable.workerId));
|
|
147
|
-
}
|
|
148
|
-
if ((_b = this.durable) === null || _b === void 0 ? void 0 : _b.workerId) {
|
|
149
|
-
promises.push(this._v1.workers.pause(this.durable.workerId));
|
|
145
|
+
var _a;
|
|
146
|
+
if (!((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)) {
|
|
147
|
+
return Promise.resolve();
|
|
150
148
|
}
|
|
151
|
-
return
|
|
149
|
+
return this._v1.workers.pause(this._internal.workerId);
|
|
152
150
|
}
|
|
153
151
|
unpause() {
|
|
154
|
-
var _a
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
promises.push(this._v1.workers.unpause(this.nonDurable.workerId));
|
|
158
|
-
}
|
|
159
|
-
if ((_b = this.durable) === null || _b === void 0 ? void 0 : _b.workerId) {
|
|
160
|
-
promises.push(this._v1.workers.unpause(this.durable.workerId));
|
|
152
|
+
var _a;
|
|
153
|
+
if (!((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)) {
|
|
154
|
+
return Promise.resolve();
|
|
161
155
|
}
|
|
162
|
-
return
|
|
156
|
+
return this._v1.workers.unpause(this._internal.workerId);
|
|
163
157
|
}
|
|
164
158
|
}
|
|
165
159
|
exports.Worker = Worker;
|
|
160
|
+
var slot_utils_2 = require("./slot-utils");
|
|
161
|
+
Object.defineProperty(exports, "__testing", { enumerable: true, get: function () { return slot_utils_2.testingExports; } });
|
package/v1/index.d.ts
CHANGED
package/v1/index.js
CHANGED
package/v1/slot-types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlotType = void 0;
|
|
4
|
+
// eslint-disable-next-line no-shadow
|
|
5
|
+
var SlotType;
|
|
6
|
+
(function (SlotType) {
|
|
7
|
+
SlotType["Default"] = "default";
|
|
8
|
+
SlotType["Durable"] = "durable";
|
|
9
|
+
})(SlotType || (exports.SlotType = SlotType = {}));
|
package/v1/task.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
103
103
|
* (optional) the concurrency options for the task
|
|
104
104
|
*/
|
|
105
105
|
concurrency?: Concurrency | Concurrency[];
|
|
106
|
+
/** @internal */
|
|
107
|
+
slotRequests?: Record<string, number>;
|
|
106
108
|
};
|
|
107
109
|
export type CreateWorkflowTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> | DurableTaskFn<I, O> = TaskFn<I, O>> = CreateBaseTaskOpts<I, O, C> & {
|
|
108
110
|
/**
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.12.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.12.1";
|
package/version.js
CHANGED
package/workflow.d.ts
CHANGED
|
@@ -380,6 +380,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
380
380
|
} | undefined;
|
|
381
381
|
}[];
|
|
382
382
|
id: string;
|
|
383
|
+
version?: string | undefined;
|
|
383
384
|
on?: {
|
|
384
385
|
cron: string;
|
|
385
386
|
event?: undefined;
|
|
@@ -388,7 +389,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
388
389
|
cron?: undefined;
|
|
389
390
|
} | undefined;
|
|
390
391
|
timeout?: string | undefined;
|
|
391
|
-
version?: string | undefined;
|
|
392
392
|
scheduleTimeout?: string | undefined;
|
|
393
393
|
sticky?: PbStickyStrategy | undefined;
|
|
394
394
|
onFailure?: {
|
|
@@ -442,6 +442,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
442
442
|
} | undefined;
|
|
443
443
|
}[];
|
|
444
444
|
id: string;
|
|
445
|
+
version?: string | undefined;
|
|
445
446
|
on?: {
|
|
446
447
|
cron: string;
|
|
447
448
|
event?: undefined;
|
|
@@ -450,7 +451,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
450
451
|
cron?: undefined;
|
|
451
452
|
} | undefined;
|
|
452
453
|
timeout?: string | undefined;
|
|
453
|
-
version?: string | undefined;
|
|
454
454
|
scheduleTimeout?: string | undefined;
|
|
455
455
|
sticky?: PbStickyStrategy | undefined;
|
|
456
456
|
onFailure?: {
|