@hatchet-dev/typescript-sdk 1.6.3 → 1.8.0
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/rest/generated/Api.d.ts +62 -1
- package/clients/rest/generated/Api.js +39 -0
- package/clients/rest/generated/data-contracts.d.ts +201 -161
- package/clients/rest/generated/data-contracts.js +168 -168
- package/package.json +2 -2
- package/protoc/v1/workflows.d.ts +11 -0
- package/protoc/v1/workflows.js +105 -3
- package/util/workflow-run-ref.js +4 -2
- package/v1/client/client.d.ts +7 -0
- package/v1/client/client.js +29 -0
- package/v1/client/features/filters.d.ts +1 -0
- package/v1/client/features/filters.js +6 -0
- package/v1/client/features/runs.d.ts +1 -0
- package/v1/client/features/runs.js +7 -0
- package/v1/client/features/tenant.d.ts +15 -0
- package/v1/client/features/tenant.js +31 -0
- package/v1/client/worker/worker-internal.js +13 -1
- package/v1/declaration.d.ts +13 -1
- package/v1/declaration.js +17 -6
- package/v1/examples/cancellations/workflow.js +2 -2
- package/v1/examples/child_workflows/workflow.js +1 -1
- package/v1/examples/on_event/workflow.d.ts +1 -0
- package/v1/examples/on_event/workflow.js +27 -1
- package/v1/examples/simple/run.js +10 -5
- package/v1/examples/sticky/workflow.js +1 -1
- package/v1/parent-run-context-vars.d.ts +15 -0
- package/v1/parent-run-context-vars.js +35 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/v1/client/client.js
CHANGED
|
@@ -21,6 +21,7 @@ const rest_1 = __importDefault(require("../../clients/rest"));
|
|
|
21
21
|
const config_loader_1 = require("../../util/config-loader");
|
|
22
22
|
const hatchet_logger_1 = require("../../clients/hatchet-client/hatchet-logger");
|
|
23
23
|
const zod_1 = require("zod");
|
|
24
|
+
const event_client_1 = require("../../clients/event/event-client");
|
|
24
25
|
const declaration_1 = require("../declaration");
|
|
25
26
|
const worker_1 = require("./worker/worker");
|
|
26
27
|
const metrics_1 = require("./features/metrics");
|
|
@@ -32,6 +33,7 @@ const admin_1 = require("./admin");
|
|
|
32
33
|
const filters_1 = require("./features/filters");
|
|
33
34
|
const schedules_1 = require("./features/schedules");
|
|
34
35
|
const crons_1 = require("./features/crons");
|
|
36
|
+
const tenant_1 = require("./features/tenant");
|
|
35
37
|
/**
|
|
36
38
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
37
39
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -75,6 +77,23 @@ class HatchetClient {
|
|
|
75
77
|
}
|
|
76
78
|
throw e;
|
|
77
79
|
}
|
|
80
|
+
try {
|
|
81
|
+
this.tenant
|
|
82
|
+
.get()
|
|
83
|
+
.then((tenant) => {
|
|
84
|
+
if (tenant.version !== 'V1') {
|
|
85
|
+
this.config
|
|
86
|
+
.logger('client-init', event_client_1.LogLevel.INFO)
|
|
87
|
+
.warn('🚨⚠️‼️ YOU ARE USING A V0 ENGINE WITH A V1 SDK, WHICH IS NOT SUPPORTED. PLEASE UPGRADE YOUR ENGINE TO V1.🚨⚠️‼️');
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
// Do nothing here
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
// Do nothing here
|
|
96
|
+
}
|
|
78
97
|
}
|
|
79
98
|
/**
|
|
80
99
|
* Static factory method to create a new Hatchet client instance.
|
|
@@ -243,6 +262,16 @@ class HatchetClient {
|
|
|
243
262
|
}
|
|
244
263
|
return this._filters;
|
|
245
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Get the tenant client for managing tenants
|
|
267
|
+
* @returns A tenant client instance
|
|
268
|
+
*/
|
|
269
|
+
get tenant() {
|
|
270
|
+
if (!this._tenant) {
|
|
271
|
+
this._tenant = new tenant_1.TenantClient(this);
|
|
272
|
+
}
|
|
273
|
+
return this._tenant;
|
|
274
|
+
}
|
|
246
275
|
/**
|
|
247
276
|
* Get the rate limits client for creating and managing rate limits
|
|
248
277
|
* @returns A rate limits client instance
|
|
@@ -18,4 +18,5 @@ export declare class FiltersClient {
|
|
|
18
18
|
get(filterId: Parameters<typeof this.api.v1FilterGet>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
19
19
|
create(opts: Parameters<typeof this.api.v1FilterCreate>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
20
20
|
delete(filterId: Parameters<typeof this.api.v1FilterDelete>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
21
|
+
update(filterId: Parameters<typeof this.api.v1FilterDelete>[1], updates: Parameters<typeof this.api.v1FilterUpdate>[2]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
21
22
|
}
|
|
@@ -55,5 +55,11 @@ class FiltersClient {
|
|
|
55
55
|
return data;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
update(filterId, updates) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { data } = yield this.api.v1FilterUpdate(this.tenantId, filterId, updates);
|
|
61
|
+
return data;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
exports.FiltersClient = FiltersClient;
|
|
@@ -62,6 +62,7 @@ export declare class RunsClient {
|
|
|
62
62
|
workflows: WorkflowsClient;
|
|
63
63
|
constructor(client: HatchetClient);
|
|
64
64
|
get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").V1WorkflowRunDetails>;
|
|
65
|
+
get_status<T = any>(run: string | WorkflowRunRef<T>): Promise<V1TaskStatus>;
|
|
65
66
|
list(opts?: Partial<ListRunsOpts>): Promise<import("../../../clients/rest/generated/data-contracts").V1TaskSummaryList>;
|
|
66
67
|
cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
67
68
|
replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
@@ -26,6 +26,13 @@ class RunsClient {
|
|
|
26
26
|
return data;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
get_status(run) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
|
|
32
|
+
const { data } = yield this.api.v1WorkflowRunGetStatus(runId);
|
|
33
|
+
return data;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
29
36
|
list(opts) {
|
|
30
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
38
|
const { data } = yield this.api.v1WorkflowRunList(this.tenantId, Object.assign({}, (yield this.prepareListFilter(opts || {}))));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tenant } from '../../../clients/rest/generated/data-contracts';
|
|
2
|
+
import { HatchetClient } from '../client';
|
|
3
|
+
/**
|
|
4
|
+
* Client for managing Tenants
|
|
5
|
+
*/
|
|
6
|
+
export declare class TenantClient {
|
|
7
|
+
api: HatchetClient['api'];
|
|
8
|
+
tenantId: string;
|
|
9
|
+
constructor(client: HatchetClient);
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the current tenant.
|
|
12
|
+
* @returns The Tenant object.
|
|
13
|
+
*/
|
|
14
|
+
get(): Promise<Tenant>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
exports.TenantClient = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Client for managing Tenants
|
|
15
|
+
*/
|
|
16
|
+
class TenantClient {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.api = client.api;
|
|
19
|
+
this.tenantId = client.tenantId;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the current tenant.
|
|
23
|
+
* @returns The Tenant object.
|
|
24
|
+
*/
|
|
25
|
+
get() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return (yield this.api.tenantGet(this.tenantId)).data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.TenantClient = TenantClient;
|
|
@@ -31,6 +31,7 @@ const transformer_1 = require("../../conditions/transformer");
|
|
|
31
31
|
const step_1 = require("../../../step");
|
|
32
32
|
const apply_namespace_1 = require("../../../util/apply-namespace");
|
|
33
33
|
const context_1 = require("./context");
|
|
34
|
+
const parent_run_context_vars_1 = require("../../parent-run-context-vars");
|
|
34
35
|
class V1Worker {
|
|
35
36
|
constructor(client, options) {
|
|
36
37
|
this.workflow_registry = [];
|
|
@@ -116,7 +117,7 @@ class V1Worker {
|
|
|
116
117
|
}
|
|
117
118
|
registerWorkflowV1(initWorkflow_1) {
|
|
118
119
|
return __awaiter(this, arguments, void 0, function* (initWorkflow, durable = false) {
|
|
119
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
120
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
120
121
|
// patch the namespace
|
|
121
122
|
const workflow = Object.assign(Object.assign({}, initWorkflow.definition), { name: (0, apply_namespace_1.applyNamespace)(initWorkflow.definition.name, this.client.config.namespace).toLowerCase() });
|
|
122
123
|
try {
|
|
@@ -240,6 +241,11 @@ class V1Worker {
|
|
|
240
241
|
});
|
|
241
242
|
}),
|
|
242
243
|
concurrency: concurrencySolo,
|
|
244
|
+
defaultFilters: (_x = (_w = workflow.defaultFilters) === null || _w === void 0 ? void 0 : _w.map((f) => ({
|
|
245
|
+
scope: f.scope,
|
|
246
|
+
expression: f.expression,
|
|
247
|
+
payload: f.payload ? JSON.stringify(f.payload) : undefined,
|
|
248
|
+
}))) !== null && _x !== void 0 ? _x : [],
|
|
243
249
|
});
|
|
244
250
|
this.registeredWorkflowPromises.push(registeredWorkflow);
|
|
245
251
|
yield registeredWorkflow;
|
|
@@ -351,6 +357,12 @@ class V1Worker {
|
|
|
351
357
|
return;
|
|
352
358
|
}
|
|
353
359
|
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
parent_run_context_vars_1.parentRunContextManager.setContext({
|
|
361
|
+
parentId: action.workflowRunId,
|
|
362
|
+
parentRunId: action.stepRunId,
|
|
363
|
+
childIndex: 0,
|
|
364
|
+
desiredWorkerId: this.workerId || '',
|
|
365
|
+
});
|
|
354
366
|
return step(context);
|
|
355
367
|
});
|
|
356
368
|
const success = (result) => __awaiter(this, void 0, void 0, function* () {
|
package/v1/declaration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WorkflowRunRef from '../util/workflow-run-ref';
|
|
2
|
-
import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
|
|
2
|
+
import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
|
|
3
3
|
import { Workflow as WorkflowV0 } from '../workflow';
|
|
4
4
|
import { IHatchetClient } from './client/client.interface';
|
|
5
5
|
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
|
|
@@ -30,6 +30,16 @@ export type RunOpts = {
|
|
|
30
30
|
* values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
|
|
31
31
|
*/
|
|
32
32
|
priority?: Priority;
|
|
33
|
+
/**
|
|
34
|
+
* (optional) if the task run should be run on the same worker.
|
|
35
|
+
* only used if spawned from within a parent task.
|
|
36
|
+
*/
|
|
37
|
+
sticky?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* (optional) the child key for the workflow run.
|
|
40
|
+
* only used if spawned from within a parent task.
|
|
41
|
+
*/
|
|
42
|
+
childKey?: string;
|
|
33
43
|
};
|
|
34
44
|
/**
|
|
35
45
|
* Helper type to safely extract output types from task results
|
|
@@ -39,6 +49,7 @@ export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key,
|
|
|
39
49
|
* Extracts a property from an object type based on task name, or falls back to inferred type
|
|
40
50
|
*/
|
|
41
51
|
export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
|
|
52
|
+
type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
|
|
42
53
|
export type CreateBaseWorkflowOpts = {
|
|
43
54
|
/**
|
|
44
55
|
* The name of the workflow.
|
|
@@ -78,6 +89,7 @@ export type CreateBaseWorkflowOpts = {
|
|
|
78
89
|
* values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
|
|
79
90
|
*/
|
|
80
91
|
defaultPriority?: Priority;
|
|
92
|
+
defaultFilters?: DefaultFilter[];
|
|
81
93
|
};
|
|
82
94
|
export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
|
|
83
95
|
export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
|
package/v1/declaration.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWork
|
|
|
13
13
|
exports.CreateTaskWorkflow = CreateTaskWorkflow;
|
|
14
14
|
exports.CreateWorkflow = CreateWorkflow;
|
|
15
15
|
exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
|
|
16
|
+
const parent_run_context_vars_1 = require("./parent-run-context-vars");
|
|
16
17
|
const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
|
|
17
18
|
// eslint-disable-next-line no-shadow
|
|
18
19
|
var Priority;
|
|
@@ -41,15 +42,25 @@ class BaseWorkflowDeclaration {
|
|
|
41
42
|
if (!this.client) {
|
|
42
43
|
throw UNBOUND_ERR;
|
|
43
44
|
}
|
|
45
|
+
// set the parent run context
|
|
46
|
+
const parentRunContext = parent_run_context_vars_1.parentRunContextManager.getContext();
|
|
47
|
+
parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(Array.isArray(input) ? input.length : 1);
|
|
48
|
+
if (!parentRunContext && ((options === null || options === void 0 ? void 0 : options.childKey) || (options === null || options === void 0 ? void 0 : options.sticky))) {
|
|
49
|
+
this.client.admin.logger.warn('ignoring childKey or sticky because run is not being spawned from a parent task');
|
|
50
|
+
}
|
|
51
|
+
const runOpts = Object.assign(Object.assign({}, options), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentStepRunId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentRunId, childIndex: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
|
|
44
52
|
if (Array.isArray(input)) {
|
|
45
53
|
let resp = [];
|
|
46
54
|
for (let i = 0; i < input.length; i += 500) {
|
|
47
55
|
const batch = input.slice(i, i + 500);
|
|
48
|
-
const batchResp = yield this.client.admin.runWorkflows(batch.map((inp) =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
const batchResp = yield this.client.admin.runWorkflows(batch.map((inp) => {
|
|
57
|
+
var _a;
|
|
58
|
+
return ({
|
|
59
|
+
workflowName: this.definition.name,
|
|
60
|
+
input: inp,
|
|
61
|
+
options: Object.assign(Object.assign({}, runOpts), { childIndex: ((_a = runOpts.childIndex) !== null && _a !== void 0 ? _a : 0) + i }),
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
53
64
|
resp = resp.concat(batchResp);
|
|
54
65
|
}
|
|
55
66
|
const res = [];
|
|
@@ -67,7 +78,7 @@ class BaseWorkflowDeclaration {
|
|
|
67
78
|
});
|
|
68
79
|
return res;
|
|
69
80
|
}
|
|
70
|
-
const res = yield this.client.admin.runWorkflow(this.definition.name, input,
|
|
81
|
+
const res = yield this.client.admin.runWorkflow(this.definition.name, input, runOpts);
|
|
71
82
|
if (_standaloneTaskName) {
|
|
72
83
|
res._standaloneTaskName = _standaloneTaskName;
|
|
73
84
|
}
|
|
@@ -19,9 +19,9 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
19
19
|
// > Declaring a Task
|
|
20
20
|
exports.cancellation = hatchet_client_1.hatchet.task({
|
|
21
21
|
name: 'cancellation',
|
|
22
|
-
fn: (
|
|
22
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
yield (0, sleep_1.default)(10 * 1000);
|
|
24
|
-
if (cancelled) {
|
|
24
|
+
if (ctx.cancelled) {
|
|
25
25
|
throw new Error('Task was cancelled');
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
@@ -27,7 +27,7 @@ exports.parent = hatchet_client_1.hatchet.task({
|
|
|
27
27
|
const n = input.N;
|
|
28
28
|
const promises = [];
|
|
29
29
|
for (let i = 0; i < n; i++) {
|
|
30
|
-
promises.push(
|
|
30
|
+
promises.push(exports.child.run({ N: i }));
|
|
31
31
|
}
|
|
32
32
|
const childRes = yield Promise.all(promises);
|
|
33
33
|
const sum = childRes.reduce((acc, curr) => acc + curr.Value, 0);
|
|
@@ -9,6 +9,7 @@ type LowerOutput = {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
12
|
+
export declare const lowerWithFilter: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
12
13
|
type UpperOutput = {
|
|
13
14
|
upper: {
|
|
14
15
|
TransformedMessage: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upper = exports.lower = exports.SIMPLE_EVENT = void 0;
|
|
3
|
+
exports.upper = exports.lowerWithFilter = exports.lower = exports.SIMPLE_EVENT = void 0;
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
5
|
exports.SIMPLE_EVENT = 'simple-event:create';
|
|
6
6
|
// > Run workflow on event
|
|
@@ -10,6 +10,24 @@ exports.lower = hatchet_client_1.hatchet.workflow({
|
|
|
10
10
|
onEvents: ['simple-event:create'],
|
|
11
11
|
});
|
|
12
12
|
// !!
|
|
13
|
+
// > Workflow with filter
|
|
14
|
+
exports.lowerWithFilter = hatchet_client_1.hatchet.workflow({
|
|
15
|
+
name: 'lower',
|
|
16
|
+
// 👀 Declare the event that will trigger the workflow
|
|
17
|
+
onEvents: ['simple-event:create'],
|
|
18
|
+
defaultFilters: [
|
|
19
|
+
{
|
|
20
|
+
expression: 'true',
|
|
21
|
+
scope: 'example-scope',
|
|
22
|
+
payload: {
|
|
23
|
+
mainCharacter: 'Anna',
|
|
24
|
+
supportingCharacter: 'Stiva',
|
|
25
|
+
location: 'Moscow',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
// !!
|
|
13
31
|
exports.lower.task({
|
|
14
32
|
name: 'lower',
|
|
15
33
|
fn: (input) => {
|
|
@@ -32,3 +50,11 @@ exports.upper.task({
|
|
|
32
50
|
};
|
|
33
51
|
},
|
|
34
52
|
});
|
|
53
|
+
// > Accessing the filter payload
|
|
54
|
+
exports.lowerWithFilter.task({
|
|
55
|
+
name: 'lowerWithFilter',
|
|
56
|
+
fn: (input, ctx) => {
|
|
57
|
+
console.log(ctx.filterPayload());
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
// !!
|
|
@@ -13,10 +13,11 @@ exports.extra = extra;
|
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
15
|
const workflow_1 = require("./workflow");
|
|
16
|
+
const workflow_with_child_1 = require("./workflow-with-child");
|
|
16
17
|
function main() {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
// > Running a Task
|
|
19
|
-
const res = yield
|
|
20
|
+
const res = yield workflow_with_child_1.parent.run({
|
|
20
21
|
Message: 'HeLlO WoRlD',
|
|
21
22
|
}, {
|
|
22
23
|
additionalMetadata: {
|
|
@@ -42,11 +43,11 @@ function extra() {
|
|
|
42
43
|
console.log(results[1].TransformedMessage);
|
|
43
44
|
// !!
|
|
44
45
|
// > Spawning Tasks from within a Task
|
|
45
|
-
const
|
|
46
|
+
const parentTask = hatchet_client_1.hatchet.task({
|
|
46
47
|
name: 'parent',
|
|
47
48
|
fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
// Simply
|
|
49
|
-
const child = yield
|
|
49
|
+
// Simply the task and it will be spawned from the parent task
|
|
50
|
+
const child = yield workflow_1.simple.run({
|
|
50
51
|
Message: 'HeLlO WoRlD',
|
|
51
52
|
});
|
|
52
53
|
return {
|
|
@@ -58,5 +59,9 @@ function extra() {
|
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
if (require.main === module) {
|
|
61
|
-
main()
|
|
62
|
+
main()
|
|
63
|
+
.catch(console.error)
|
|
64
|
+
.finally(() => {
|
|
65
|
+
process.exit(0);
|
|
66
|
+
});
|
|
62
67
|
}
|
|
@@ -21,7 +21,7 @@ exports.sticky = hatchet_client_1.hatchet.task({
|
|
|
21
21
|
sticky: workflows_1.StickyStrategy.SOFT,
|
|
22
22
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
// specify a child workflow to run on the same worker
|
|
24
|
-
const result = yield
|
|
24
|
+
const result = yield workflow_1.child.run({
|
|
25
25
|
N: 1,
|
|
26
26
|
}, { sticky: true });
|
|
27
27
|
return {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ParentRunContext {
|
|
2
|
+
parentId: string;
|
|
3
|
+
parentRunId: string;
|
|
4
|
+
desiredWorkerId: string;
|
|
5
|
+
childIndex?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class ParentRunContextManager {
|
|
8
|
+
private storage;
|
|
9
|
+
constructor();
|
|
10
|
+
setContext(opts: ParentRunContext): void;
|
|
11
|
+
setParentRunIdAndIncrementChildIndex(opts: ParentRunContext): void;
|
|
12
|
+
incrementChildIndex(n: number): void;
|
|
13
|
+
getContext(): ParentRunContext | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare const parentRunContextManager: ParentRunContextManager;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parentRunContextManager = exports.ParentRunContextManager = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
class ParentRunContextManager {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.storage = new async_hooks_1.AsyncLocalStorage();
|
|
8
|
+
}
|
|
9
|
+
setContext(opts) {
|
|
10
|
+
this.storage.enterWith(Object.assign({}, opts));
|
|
11
|
+
}
|
|
12
|
+
setParentRunIdAndIncrementChildIndex(opts) {
|
|
13
|
+
var _a;
|
|
14
|
+
const parentRunContext = this.getContext();
|
|
15
|
+
if (parentRunContext) {
|
|
16
|
+
parentRunContext.parentId = opts.parentId;
|
|
17
|
+
parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
18
|
+
this.setContext(parentRunContext);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
incrementChildIndex(n) {
|
|
22
|
+
var _a;
|
|
23
|
+
const parentRunContext = this.getContext();
|
|
24
|
+
if (parentRunContext) {
|
|
25
|
+
parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + n;
|
|
26
|
+
this.setContext(parentRunContext);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getContext() {
|
|
30
|
+
return this.storage.getStore();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ParentRunContextManager = ParentRunContextManager;
|
|
34
|
+
// Export a default instance for backward compatibility and convenience
|
|
35
|
+
exports.parentRunContextManager = new ParentRunContextManager();
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.8.0";
|
package/version.js
CHANGED