@hatchet-dev/typescript-sdk 1.0.0-alpha2 → 1.0.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/admin/admin-client.d.ts +3 -1
- package/clients/admin/admin-client.js +5 -4
- package/clients/hatchet-client/hatchet-client.d.ts +3 -1
- package/clients/hatchet-client/hatchet-client.js +3 -2
- package/clients/worker/worker.js +4 -4
- package/package.json +1 -1
- package/step.d.ts +2 -0
- package/step.js +7 -0
- package/util/sleep.d.ts +1 -0
- package/util/sleep.js +1 -0
- package/util/workflow-run-ref.d.ts +5 -1
- package/util/workflow-run-ref.js +25 -1
- package/v1/client/client.d.ts +4 -2
- package/v1/client/client.js +26 -7
- package/v1/client/features/runs.d.ts +21 -2
- package/v1/client/features/runs.js +24 -10
- package/v1/declaration.d.ts +1 -1
- package/v1/examples/cancellations/run.d.ts +1 -0
- package/v1/examples/cancellations/run.js +50 -0
- package/v1/examples/cancellations/worker.d.ts +1 -0
- package/v1/examples/cancellations/worker.js +29 -0
- package/v1/examples/cancellations/workflow.d.ts +3 -0
- package/v1/examples/cancellations/workflow.js +33 -0
- package/v1/examples/child_workflows/run.js +1 -1
- package/v1/examples/child_workflows/workflow.d.ts +6 -12
- package/v1/examples/child_workflows/workflow.js +5 -11
- package/v1/examples/dag/workflow.js +5 -0
- package/v1/examples/landing_page/durable-excution.d.ts +3 -0
- package/v1/examples/landing_page/durable-excution.js +40 -0
- package/v1/examples/landing_page/event-signaling.d.ts +6 -0
- package/v1/examples/landing_page/event-signaling.js +16 -0
- package/v1/examples/landing_page/flow-control.d.ts +6 -0
- package/v1/examples/landing_page/flow-control.js +26 -0
- package/v1/examples/landing_page/queues.d.ts +3 -0
- package/v1/examples/landing_page/queues.js +33 -0
- package/v1/examples/landing_page/scheduling.d.ts +1 -0
- package/v1/examples/landing_page/scheduling.js +12 -0
- package/v1/examples/landing_page/task-routing.d.ts +6 -0
- package/v1/examples/landing_page/task-routing.js +25 -0
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_failure/workflow.js +4 -5
- package/v1/examples/retries/run.d.ts +1 -0
- package/v1/examples/retries/run.js +29 -0
- package/v1/examples/retries/worker.d.ts +1 -0
- package/v1/examples/retries/worker.js +24 -0
- package/v1/examples/retries/workflow.d.ts +5 -0
- package/v1/examples/retries/workflow.js +53 -0
- package/v1/examples/simple/run.js +1 -1
- package/v1/examples/sticky/run.d.ts +1 -0
- package/v1/examples/sticky/run.js +29 -0
- package/v1/examples/sticky/worker.d.ts +1 -0
- package/v1/examples/sticky/worker.js +24 -0
- package/v1/examples/sticky/workflow.d.ts +5 -0
- package/v1/examples/sticky/workflow.js +32 -0
- package/v1/examples/timeouts/run.d.ts +1 -0
- package/v1/examples/timeouts/run.js +29 -0
- package/v1/examples/timeouts/worker.d.ts +1 -0
- package/v1/examples/timeouts/worker.js +29 -0
- package/v1/examples/timeouts/workflow.d.ts +3 -0
- package/v1/examples/timeouts/workflow.js +34 -0
- package/v1/examples/with_timeouts/workflow.d.ts +9 -0
- package/v1/examples/with_timeouts/workflow.js +62 -0
- package/v1/task.d.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -4,6 +4,7 @@ import { ClientConfig } from '../hatchet-client/client-config';
|
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
5
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
6
6
|
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
7
|
+
import { RunsClient } from '../../v1';
|
|
7
8
|
import { Api } from '../rest';
|
|
8
9
|
import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
9
10
|
import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
|
|
@@ -32,7 +33,8 @@ export declare class AdminClient {
|
|
|
32
33
|
tenantId: string;
|
|
33
34
|
logger: Logger;
|
|
34
35
|
listenerClient: RunListenerClient;
|
|
35
|
-
|
|
36
|
+
workflows: RunsClient | undefined;
|
|
37
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api, tenantId: string, listenerClient: RunListenerClient, workflows: RunsClient | undefined);
|
|
36
38
|
/**
|
|
37
39
|
* @deprecated use putWorkflow instead
|
|
38
40
|
*/
|
|
@@ -19,7 +19,7 @@ const retrier_1 = require("../../util/retrier");
|
|
|
19
19
|
const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
|
|
20
20
|
const workflows_2 = require("../../protoc/v1/workflows");
|
|
21
21
|
class AdminClient {
|
|
22
|
-
constructor(config, channel, factory, api, tenantId, listenerClient) {
|
|
22
|
+
constructor(config, channel, factory, api, tenantId, listenerClient, workflows) {
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
25
25
|
this.v1Client = factory.create(workflows_2.AdminServiceDefinition, channel);
|
|
@@ -27,6 +27,7 @@ class AdminClient {
|
|
|
27
27
|
this.tenantId = tenantId;
|
|
28
28
|
this.logger = config.logger(`Admin`, config.log_level);
|
|
29
29
|
this.listenerClient = listenerClient;
|
|
30
|
+
this.workflows = workflows;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* @deprecated use putWorkflow instead
|
|
@@ -124,7 +125,7 @@ class AdminClient {
|
|
|
124
125
|
const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
125
126
|
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
126
127
|
: undefined }));
|
|
127
|
-
return new workflow_run_ref_1.default(resp, this.listenerClient, options === null || options === void 0 ? void 0 : options.parentId);
|
|
128
|
+
return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
|
|
128
129
|
}
|
|
129
130
|
catch (e) {
|
|
130
131
|
throw new hatchet_error_1.default(e.message);
|
|
@@ -156,7 +157,7 @@ class AdminClient {
|
|
|
156
157
|
return bulkTriggerWorkflowResponse.then((res) => {
|
|
157
158
|
return res.workflowRunIds.map((resp, index) => {
|
|
158
159
|
const { options } = workflowRuns[index];
|
|
159
|
-
return new workflow_run_ref_1.default(resp, this.listenerClient, options === null || options === void 0 ? void 0 : options.parentId);
|
|
160
|
+
return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
|
|
160
161
|
});
|
|
161
162
|
});
|
|
162
163
|
}
|
|
@@ -238,7 +239,7 @@ class AdminClient {
|
|
|
238
239
|
*/
|
|
239
240
|
getWorkflowRun(workflowRunId) {
|
|
240
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
return new workflow_run_ref_1.default(workflowRunId, this.listenerClient);
|
|
242
|
+
return new workflow_run_ref_1.default(workflowRunId, this.listenerClient, this.workflows);
|
|
242
243
|
});
|
|
243
244
|
}
|
|
244
245
|
/**
|
|
@@ -6,6 +6,7 @@ import { Workflow as V0Workflow } from '../../workflow';
|
|
|
6
6
|
import { V0Worker, WorkerOpts } from '../worker';
|
|
7
7
|
import { AxiosRequestConfig } from 'axios';
|
|
8
8
|
import { Logger } from '../../util/logger';
|
|
9
|
+
import { RunsClient } from '../../v1';
|
|
9
10
|
import { ClientConfig } from './client-config';
|
|
10
11
|
import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
|
|
11
12
|
import { Api } from '../rest/generated/Api';
|
|
@@ -25,13 +26,14 @@ export declare class InternalHatchetClient {
|
|
|
25
26
|
dispatcher: DispatcherClient;
|
|
26
27
|
admin: AdminClient;
|
|
27
28
|
api: Api;
|
|
29
|
+
runs: RunsClient | undefined;
|
|
28
30
|
listener: RunListenerClient;
|
|
29
31
|
tenantId: string;
|
|
30
32
|
durableListener: DurableListenerClient;
|
|
31
33
|
logger: Logger;
|
|
32
34
|
cron: CronClient;
|
|
33
35
|
schedule: ScheduleClient;
|
|
34
|
-
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosOpts?: AxiosRequestConfig);
|
|
36
|
+
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosOpts?: AxiosRequestConfig, runs?: RunsClient);
|
|
35
37
|
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): InternalHatchetClient;
|
|
36
38
|
run(workflow: string | V0Workflow): Promise<V0Worker>;
|
|
37
39
|
worker(workflow: string | V0Workflow, opts?: Omit<WorkerOpts, 'name'> | number): Promise<V0Worker>;
|
|
@@ -90,10 +90,11 @@ const addTokenMiddleware = (token) => function _(call, options) {
|
|
|
90
90
|
};
|
|
91
91
|
exports.addTokenMiddleware = addTokenMiddleware;
|
|
92
92
|
class InternalHatchetClient {
|
|
93
|
-
constructor(config, options, axiosOpts) {
|
|
93
|
+
constructor(config, options, axiosOpts, runs) {
|
|
94
94
|
// Initializes a new Client instance.
|
|
95
95
|
// Loads config in the following order: config param > yaml file > env vars
|
|
96
96
|
var _a;
|
|
97
|
+
this.runs = runs;
|
|
97
98
|
const loaded = config_loader_1.ConfigLoader.loadClientConfig(config, {
|
|
98
99
|
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
99
100
|
});
|
|
@@ -119,7 +120,7 @@ class InternalHatchetClient {
|
|
|
119
120
|
this.event = new event_client_1.EventClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
120
121
|
this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
121
122
|
this.listener = new child_listener_client_1.RunListenerClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api);
|
|
122
|
-
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId, this.listener);
|
|
123
|
+
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId, this.listener, this.runs);
|
|
123
124
|
this.durableListener = new durable_listener_client_1.DurableListenerClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api);
|
|
124
125
|
this.logger = this.config.logger('HatchetClient', this.config.log_level);
|
|
125
126
|
this.logger.debug(`Initialized HatchetClient`);
|
package/clients/worker/worker.js
CHANGED
|
@@ -138,7 +138,7 @@ class V0Worker {
|
|
|
138
138
|
parents: [],
|
|
139
139
|
retries: onFailure.retries || ((_c = workflow.taskDefaults) === null || _c === void 0 ? void 0 : _c.retries) || 0,
|
|
140
140
|
rateLimits: (0, step_1.mapRateLimit)(onFailure.rateLimits || ((_d = workflow.taskDefaults) === null || _d === void 0 ? void 0 : _d.rateLimits)),
|
|
141
|
-
workerLabels: toPbWorkerLabel(onFailure.
|
|
141
|
+
workerLabels: toPbWorkerLabel(onFailure.desiredWorkerLabels || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.workerLabels)),
|
|
142
142
|
concurrency: [],
|
|
143
143
|
backoffFactor: ((_f = onFailure.backoff) === null || _f === void 0 ? void 0 : _f.factor) || ((_h = (_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.backoff) === null || _h === void 0 ? void 0 : _h.factor),
|
|
144
144
|
backoffMaxSeconds: ((_j = onFailure.backoff) === null || _j === void 0 ? void 0 : _j.maxSeconds) || ((_l = (_k = workflow.taskDefaults) === null || _k === void 0 ? void 0 : _k.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds),
|
|
@@ -154,7 +154,7 @@ class V0Worker {
|
|
|
154
154
|
parents,
|
|
155
155
|
retries: 0,
|
|
156
156
|
rateLimits: [],
|
|
157
|
-
|
|
157
|
+
desiredWorkerLabels: {},
|
|
158
158
|
concurrency: [],
|
|
159
159
|
};
|
|
160
160
|
}
|
|
@@ -169,7 +169,7 @@ class V0Worker {
|
|
|
169
169
|
parents,
|
|
170
170
|
retries: onSuccess.retries || ((_p = workflow.taskDefaults) === null || _p === void 0 ? void 0 : _p.retries) || 0,
|
|
171
171
|
rateLimits: onSuccess.rateLimits || ((_q = workflow.taskDefaults) === null || _q === void 0 ? void 0 : _q.rateLimits),
|
|
172
|
-
|
|
172
|
+
desiredWorkerLabels: onSuccess.desiredWorkerLabels || ((_r = workflow.taskDefaults) === null || _r === void 0 ? void 0 : _r.workerLabels),
|
|
173
173
|
concurrency: onSuccess.concurrency || ((_s = workflow.taskDefaults) === null || _s === void 0 ? void 0 : _s.concurrency),
|
|
174
174
|
backoff: onSuccess.backoff || ((_t = workflow.taskDefaults) === null || _t === void 0 ? void 0 : _t.backoff),
|
|
175
175
|
};
|
|
@@ -213,7 +213,7 @@ class V0Worker {
|
|
|
213
213
|
userData: '{}',
|
|
214
214
|
retries: task.retries || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.retries) || 0,
|
|
215
215
|
rateLimits: (0, step_1.mapRateLimit)(task.rateLimits || ((_f = workflow.taskDefaults) === null || _f === void 0 ? void 0 : _f.rateLimits)),
|
|
216
|
-
workerLabels: toPbWorkerLabel(task.
|
|
216
|
+
workerLabels: toPbWorkerLabel(task.desiredWorkerLabels || ((_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.workerLabels)),
|
|
217
217
|
backoffFactor: ((_h = task.backoff) === null || _h === void 0 ? void 0 : _h.factor) || ((_k = (_j = workflow.taskDefaults) === null || _j === void 0 ? void 0 : _j.backoff) === null || _k === void 0 ? void 0 : _k.factor),
|
|
218
218
|
backoffMaxSeconds: ((_l = task.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds) || ((_o = (_m = workflow.taskDefaults) === null || _m === void 0 ? void 0 : _m.backoff) === null || _o === void 0 ? void 0 : _o.maxSeconds),
|
|
219
219
|
conditions: (0, transformer_1.taskConditionsToPb)(task),
|
package/package.json
CHANGED
package/step.d.ts
CHANGED
|
@@ -207,6 +207,8 @@ export declare class Context<T, K = {}> {
|
|
|
207
207
|
logger: Logger;
|
|
208
208
|
spawnIndex: number;
|
|
209
209
|
constructor(action: Action, client: InternalHatchetClient, worker: V0Worker);
|
|
210
|
+
get abortController(): AbortController;
|
|
211
|
+
get cancelled(): boolean;
|
|
210
212
|
/**
|
|
211
213
|
* Retrieves the output of a parent task.
|
|
212
214
|
* @param task - The name of the task or a CreateTaskOpts object.
|
package/step.js
CHANGED
|
@@ -130,6 +130,7 @@ class ContextWorker {
|
|
|
130
130
|
exports.ContextWorker = ContextWorker;
|
|
131
131
|
class Context {
|
|
132
132
|
constructor(action, client, worker) {
|
|
133
|
+
// @deprecated use ctx.abortController instead
|
|
133
134
|
this.controller = new AbortController();
|
|
134
135
|
this.overridesData = {};
|
|
135
136
|
this.spawnIndex = 0;
|
|
@@ -153,6 +154,12 @@ class Context {
|
|
|
153
154
|
throw new hatchet_error_1.default(`Could not parse payload: ${e.message}`);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
157
|
+
get abortController() {
|
|
158
|
+
return this.controller;
|
|
159
|
+
}
|
|
160
|
+
get cancelled() {
|
|
161
|
+
return this.controller.signal.aborted;
|
|
162
|
+
}
|
|
156
163
|
/**
|
|
157
164
|
* Retrieves the output of a parent task.
|
|
158
165
|
* @param task - The name of the task or a CreateTaskOpts object.
|
package/util/sleep.d.ts
CHANGED
package/util/sleep.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/**
|
|
4
4
|
* Sleeps for a given number of milliseconds without blocking the event loop
|
|
5
|
+
*
|
|
5
6
|
* WARNING: This is not a durable sleep. It will not be honored if the worker is
|
|
6
7
|
* restarted or crashes.
|
|
7
8
|
* @param ms - The number of milliseconds to sleep
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RunListenerClient, StepRunEvent } from '../clients/listeners/run-listener/child-listener-client';
|
|
2
|
+
import { RunsClient } from '../v1';
|
|
2
3
|
type EventualWorkflowRunId = string | Promise<string> | Promise<{
|
|
3
4
|
workflowRunId: string;
|
|
4
5
|
}>;
|
|
@@ -9,9 +10,10 @@ export default class WorkflowRunRef<T> {
|
|
|
9
10
|
workflowRunId: EventualWorkflowRunId;
|
|
10
11
|
parentWorkflowRunId?: string;
|
|
11
12
|
private client;
|
|
13
|
+
private runs;
|
|
12
14
|
constructor(workflowRunId: string | Promise<string> | Promise<{
|
|
13
15
|
workflowRunId: string;
|
|
14
|
-
}>, client: RunListenerClient, parentWorkflowRunId?: string);
|
|
16
|
+
}>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string);
|
|
15
17
|
get runId(): Promise<string>;
|
|
16
18
|
getWorkflowRunId(): Promise<string>;
|
|
17
19
|
stream(): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
|
|
@@ -22,5 +24,7 @@ export default class WorkflowRunRef<T> {
|
|
|
22
24
|
*/
|
|
23
25
|
result(): Promise<T>;
|
|
24
26
|
toJSON(): Promise<string>;
|
|
27
|
+
cancel(): Promise<void>;
|
|
28
|
+
replay(): Promise<void>;
|
|
25
29
|
}
|
|
26
30
|
export {};
|
package/util/workflow-run-ref.js
CHANGED
|
@@ -50,10 +50,11 @@ function getWorkflowRunId(workflowRunId) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
class WorkflowRunRef {
|
|
53
|
-
constructor(workflowRunId, client, parentWorkflowRunId) {
|
|
53
|
+
constructor(workflowRunId, client, runsClient, parentWorkflowRunId) {
|
|
54
54
|
this.workflowRunId = workflowRunId;
|
|
55
55
|
this.parentWorkflowRunId = parentWorkflowRunId;
|
|
56
56
|
this.client = client;
|
|
57
|
+
this.runs = runsClient;
|
|
57
58
|
}
|
|
58
59
|
// TODO docstrings
|
|
59
60
|
get runId() {
|
|
@@ -73,6 +74,7 @@ class WorkflowRunRef {
|
|
|
73
74
|
}
|
|
74
75
|
// TODO not sure if i want this to be a get since it might be blocking for a long time..
|
|
75
76
|
get output() {
|
|
77
|
+
// TODO output for single task workflows
|
|
76
78
|
return this.result();
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
@@ -143,5 +145,27 @@ class WorkflowRunRef {
|
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
}
|
|
148
|
+
cancel() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
if (!this.runs) {
|
|
151
|
+
throw new Error('cancel is a v1 only feature, please upgrade your sdk');
|
|
152
|
+
}
|
|
153
|
+
const workflowRunId = yield getWorkflowRunId(this.workflowRunId);
|
|
154
|
+
yield this.runs.cancel({
|
|
155
|
+
ids: [workflowRunId],
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
replay() {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
if (!this.runs) {
|
|
162
|
+
throw new Error('replay is a v1 only feature, please upgrade your sdk');
|
|
163
|
+
}
|
|
164
|
+
const workflowRunId = yield getWorkflowRunId(this.workflowRunId);
|
|
165
|
+
yield this.runs.replay({
|
|
166
|
+
ids: [workflowRunId],
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
146
170
|
}
|
|
147
171
|
exports.default = WorkflowRunRef;
|
package/v1/client/client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
3
3
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
4
4
|
import { Workflow as V0Workflow } from '../../workflow';
|
|
5
5
|
import { JsonObject, DurableContext } from '../../step';
|
|
6
|
+
import { Api } from '../../clients/rest';
|
|
6
7
|
import { CreateTaskWorkflowOpts, CreateWorkflowOpts, RunOpts, BaseWorkflowDeclaration, WorkflowDeclaration, TaskWorkflowDeclaration } from '../declaration';
|
|
7
8
|
import { IHatchetClient } from './client.interface';
|
|
8
9
|
import { CreateWorkerOpts, Worker } from './worker';
|
|
@@ -18,12 +19,13 @@ import { CreateStandaloneDurableTaskOpts } from '../task';
|
|
|
18
19
|
export declare class HatchetClient implements IHatchetClient {
|
|
19
20
|
/** The underlying v0 client instance */
|
|
20
21
|
_v0: InternalHatchetClient;
|
|
22
|
+
_api: Api;
|
|
21
23
|
/**
|
|
22
24
|
* @deprecated v0 client will be removed in a future release, please upgrade to v1
|
|
23
25
|
*/
|
|
24
26
|
get v0(): InternalHatchetClient;
|
|
25
27
|
/** The tenant ID for the Hatchet client */
|
|
26
|
-
|
|
28
|
+
tenantId: string;
|
|
27
29
|
_isV1: boolean | undefined;
|
|
28
30
|
get isV1(): boolean;
|
|
29
31
|
/**
|
|
@@ -179,7 +181,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
179
181
|
* Note: This is not recommended for general use, but is available for advanced scenarios
|
|
180
182
|
* @returns A API client instance
|
|
181
183
|
*/
|
|
182
|
-
get api():
|
|
184
|
+
get api(): Api<unknown>;
|
|
183
185
|
/**
|
|
184
186
|
* @deprecated use workflow.run, client.run, or client.* feature methods instead
|
|
185
187
|
*/
|
package/v1/client/client.js
CHANGED
|
@@ -17,6 +17,10 @@ exports.HatchetClient = void 0;
|
|
|
17
17
|
/* eslint-disable no-underscore-dangle */
|
|
18
18
|
const hatchet_client_1 = require("../../clients/hatchet-client");
|
|
19
19
|
const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
|
|
20
|
+
const rest_1 = __importDefault(require("../../clients/rest"));
|
|
21
|
+
const config_loader_1 = require("../../util/config-loader");
|
|
22
|
+
const hatchet_logger_1 = require("../../clients/hatchet-client/hatchet-logger");
|
|
23
|
+
const zod_1 = require("zod");
|
|
20
24
|
const declaration_1 = require("../declaration");
|
|
21
25
|
const worker_1 = require("./worker");
|
|
22
26
|
const metrics_1 = require("./features/metrics");
|
|
@@ -34,10 +38,6 @@ class HatchetClient {
|
|
|
34
38
|
get v0() {
|
|
35
39
|
return this._v0;
|
|
36
40
|
}
|
|
37
|
-
/** The tenant ID for the Hatchet client */
|
|
38
|
-
get tenantId() {
|
|
39
|
-
return this._v0.tenantId;
|
|
40
|
-
}
|
|
41
41
|
get isV1() {
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
@@ -49,7 +49,26 @@ class HatchetClient {
|
|
|
49
49
|
*/
|
|
50
50
|
constructor(config, options, axiosConfig) {
|
|
51
51
|
this._isV1 = true;
|
|
52
|
-
|
|
52
|
+
try {
|
|
53
|
+
const loaded = config_loader_1.ConfigLoader.loadClientConfig(config, {
|
|
54
|
+
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
55
|
+
});
|
|
56
|
+
const valid = hatchet_client_1.ClientConfigSchema.parse(loaded);
|
|
57
|
+
let logConstructor = config === null || config === void 0 ? void 0 : config.logger;
|
|
58
|
+
if (logConstructor == null) {
|
|
59
|
+
logConstructor = hatchet_logger_1.DEFAULT_LOGGER;
|
|
60
|
+
}
|
|
61
|
+
const clientConfig = Object.assign(Object.assign({}, valid), { logger: logConstructor });
|
|
62
|
+
this.tenantId = clientConfig.tenant_id;
|
|
63
|
+
this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
|
|
64
|
+
this._v0 = new hatchet_client_1.InternalHatchetClient(clientConfig, options, axiosConfig, this.runs);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
68
|
+
throw new Error(`Invalid client config: ${e.message}`);
|
|
69
|
+
}
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
53
72
|
}
|
|
54
73
|
/**
|
|
55
74
|
* Static factory method to create a new Hatchet client instance.
|
|
@@ -227,7 +246,7 @@ class HatchetClient {
|
|
|
227
246
|
* @returns A API client instance
|
|
228
247
|
*/
|
|
229
248
|
get api() {
|
|
230
|
-
return this.
|
|
249
|
+
return this._api;
|
|
231
250
|
}
|
|
232
251
|
/**
|
|
233
252
|
* @deprecated use workflow.run, client.run, or client.* feature methods instead
|
|
@@ -259,7 +278,7 @@ class HatchetClient {
|
|
|
259
278
|
return this._v0.webhooks(workflows);
|
|
260
279
|
}
|
|
261
280
|
runRef(id) {
|
|
262
|
-
return new workflow_run_ref_1.default(id, this.v0.listener);
|
|
281
|
+
return new workflow_run_ref_1.default(id, this.v0.listener, this.runs);
|
|
263
282
|
}
|
|
264
283
|
}
|
|
265
284
|
exports.HatchetClient = HatchetClient;
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import WorkflowRunRef from '../../../util/workflow-run-ref';
|
|
2
|
+
import { V1TaskStatus } from '../../../clients/rest/generated/data-contracts';
|
|
2
3
|
import { HatchetClient } from '../client';
|
|
4
|
+
import { WorkflowsClient } from './workflows';
|
|
5
|
+
export type RunFilter = {
|
|
6
|
+
since: Date;
|
|
7
|
+
until?: Date;
|
|
8
|
+
statuses?: V1TaskStatus[];
|
|
9
|
+
workflowNames?: string[];
|
|
10
|
+
additionalMetadata?: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
export type CancelRunOpts = {
|
|
13
|
+
ids?: string[];
|
|
14
|
+
filters?: RunFilter;
|
|
15
|
+
};
|
|
16
|
+
export type ReplayRunOpts = {
|
|
17
|
+
ids?: string[];
|
|
18
|
+
filters?: RunFilter;
|
|
19
|
+
};
|
|
3
20
|
/**
|
|
4
21
|
* RunsClient is used to list and manage runs
|
|
5
22
|
*/
|
|
6
23
|
export declare class RunsClient {
|
|
7
24
|
api: HatchetClient['api'];
|
|
8
25
|
tenantId: string;
|
|
26
|
+
workflows: WorkflowsClient;
|
|
9
27
|
constructor(client: HatchetClient);
|
|
10
28
|
get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRun>;
|
|
11
29
|
getDetails<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunShape>;
|
|
12
30
|
list(opts?: Parameters<typeof this.api.workflowRunList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunList>;
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
32
|
+
replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
33
|
+
private prepareFilter;
|
|
15
34
|
}
|
|
@@ -17,6 +17,7 @@ class RunsClient {
|
|
|
17
17
|
constructor(client) {
|
|
18
18
|
this.api = client.api;
|
|
19
19
|
this.tenantId = client.tenantId;
|
|
20
|
+
this.workflows = client.workflows;
|
|
20
21
|
}
|
|
21
22
|
// TODO expose streaming methods?
|
|
22
23
|
get(run) {
|
|
@@ -40,20 +41,33 @@ class RunsClient {
|
|
|
40
41
|
return data;
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
cancel(opts) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const filter = opts.filters && (yield this.prepareFilter(opts.filters));
|
|
47
|
+
return this.api.v1TaskCancel(this.tenantId, {
|
|
48
|
+
externalIds: opts.ids,
|
|
49
|
+
filter,
|
|
50
|
+
});
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
replay(opts) {
|
|
52
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const filter = opts.filters && (yield this.prepareFilter(opts.filters));
|
|
56
|
+
return this.api.v1TaskReplay(this.tenantId, {
|
|
57
|
+
externalIds: opts.ids,
|
|
58
|
+
filter,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
prepareFilter(_a) {
|
|
63
|
+
return __awaiter(this, arguments, void 0, function* ({ since, until, statuses, workflowNames, additionalMetadata, }) {
|
|
64
|
+
return {
|
|
65
|
+
since: since.toISOString(),
|
|
66
|
+
until: until === null || until === void 0 ? void 0 : until.toISOString(),
|
|
67
|
+
statuses,
|
|
68
|
+
workflowIds: yield Promise.all((workflowNames === null || workflowNames === void 0 ? void 0 : workflowNames.map((name) => __awaiter(this, void 0, void 0, function* () { return (yield this.workflows.get(name)).metadata.id; }))) || []),
|
|
69
|
+
additionalMetadata: Object.entries(additionalMetadata || {}).map(([key, value]) => `${key}:${value}`),
|
|
70
|
+
};
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
73
|
}
|
package/v1/declaration.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export type TaskDefaults = {
|
|
|
120
120
|
* - weight: Priority weight for worker selection
|
|
121
121
|
* - comparator: Custom comparison logic for label matching
|
|
122
122
|
*/
|
|
123
|
-
workerLabels?: CreateWorkflowTaskOpts<any, any>['
|
|
123
|
+
workerLabels?: CreateWorkflowTaskOpts<any, any>['desiredWorkerLabels'];
|
|
124
124
|
/**
|
|
125
125
|
* (optional) the concurrency options for the task.
|
|
126
126
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
/* eslint-disable no-console */
|
|
16
|
+
// ❓ Running a Task with Results
|
|
17
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
|
+
const workflow_1 = require("./workflow");
|
|
19
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
20
|
+
// ...
|
|
21
|
+
function main() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const run = workflow_1.cancellation.runNoWait({});
|
|
24
|
+
yield (0, sleep_1.default)(1000);
|
|
25
|
+
yield run.cancel();
|
|
26
|
+
const res = yield run.output;
|
|
27
|
+
console.log(res);
|
|
28
|
+
yield (0, sleep_1.default)(1000);
|
|
29
|
+
yield run.replay();
|
|
30
|
+
const resReplay = yield run.output;
|
|
31
|
+
console.log(resReplay);
|
|
32
|
+
const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
|
|
33
|
+
const run4 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
|
|
34
|
+
yield (0, sleep_1.default)(1000);
|
|
35
|
+
yield hatchet_client_1.hatchet.runs.cancel({
|
|
36
|
+
filters: {
|
|
37
|
+
since: new Date(Date.now() - 60 * 60),
|
|
38
|
+
additionalMetadata: { test: 'test' },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const res3 = yield Promise.all([run2.output, run4.output]);
|
|
42
|
+
console.log(res3);
|
|
43
|
+
// !!
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (require.main === module) {
|
|
47
|
+
main()
|
|
48
|
+
.catch(console.error)
|
|
49
|
+
.finally(() => process.exit(0));
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
// ❓ Declaring a Worker
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
function main() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const worker = yield hatchet_client_1.hatchet.worker('cancellation-worker', {
|
|
18
|
+
// 👀 Declare the workflows that the worker can execute
|
|
19
|
+
workflows: [workflow_1.cancellation],
|
|
20
|
+
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
21
|
+
slots: 100,
|
|
22
|
+
});
|
|
23
|
+
yield worker.start();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
main();
|
|
28
|
+
}
|
|
29
|
+
// !!
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.cancellation = void 0;
|
|
16
|
+
// ❓ Declaring a Task
|
|
17
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
// (optional) Define the input type for the workflow
|
|
20
|
+
exports.cancellation = hatchet_client_1.hatchet.task({
|
|
21
|
+
name: 'cancellation',
|
|
22
|
+
fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { cancelled }) {
|
|
23
|
+
yield (0, sleep_1.default)(10 * 1000);
|
|
24
|
+
if (cancelled) {
|
|
25
|
+
throw new Error('Task was cancelled');
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
Completed: true,
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
// !!
|
|
33
|
+
// see ./worker.ts and ./run.ts for how to run the workflow
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
type ChildInput = {
|
|
2
2
|
N: number;
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export declare const child: import("../..").WorkflowDeclaration<ChildInput, ChildOutput>;
|
|
4
|
+
export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
|
|
5
|
+
Value: number;
|
|
6
|
+
}>;
|
|
10
7
|
type ParentInput = {
|
|
11
8
|
N: number;
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export declare const parent: import("../..").WorkflowDeclaration<ParentInput, ParentOutput>;
|
|
10
|
+
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
11
|
+
Result: number;
|
|
12
|
+
}>;
|
|
19
13
|
export {};
|