@hatchet-dev/typescript-sdk 0.20.2 → 1.0.0-alpha0
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/hatchet-client/features/cron-client.d.ts +0 -1
- package/clients/hatchet-client/features/cron-client.js +6 -3
- package/clients/hatchet-client/hatchet-client.d.ts +8 -7
- package/clients/hatchet-client/hatchet-client.js +9 -8
- package/clients/hatchet-client/hatchet-logger.js +2 -2
- package/clients/listener/listener-client.js +1 -0
- package/clients/rest/generated/Api.d.ts +201 -1
- package/clients/rest/generated/Api.js +108 -0
- package/clients/rest/generated/data-contracts.d.ts +270 -8
- package/clients/rest/generated/data-contracts.js +20 -1
- package/clients/worker/handler.d.ts +2 -2
- package/clients/worker/worker.d.ts +4 -4
- package/clients/worker/worker.js +3 -3
- package/examples/api.js +1 -1
- package/examples/example-event-with-results.js +1 -1
- package/examples/stream-by-additional-meta.js +1 -1
- package/index.d.ts +3 -1
- package/index.js +5 -3
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.d.ts +2 -0
- package/protoc/dispatcher/dispatcher.js +17 -1
- package/protoc/workflows/v1-admin.d.ts +79 -0
- package/protoc/workflows/v1-admin.js +529 -0
- package/sdk.d.ts +1 -1
- package/sdk.js +2 -2
- package/step.d.ts +75 -9
- package/step.js +65 -2
- package/util/hatchet-promise/hatchet-promise.js +1 -0
- package/v1/client/client.d.ts +81 -0
- package/v1/client/client.interface.d.ts +4 -0
- package/v1/client/client.interface.js +2 -0
- package/v1/client/client.js +134 -0
- package/v1/client/worker.d.ts +82 -0
- package/v1/client/worker.js +125 -0
- package/v1/examples/child_workflows/run.d.ts +1 -0
- package/v1/examples/child_workflows/run.js +30 -0
- package/v1/examples/child_workflows/worker.d.ts +1 -0
- package/v1/examples/child_workflows/worker.js +24 -0
- package/v1/examples/child_workflows/workflow.d.ts +19 -0
- package/v1/examples/child_workflows/workflow.js +43 -0
- package/v1/examples/client.d.ts +2 -0
- package/v1/examples/client.js +5 -0
- package/v1/examples/concurrency-rr/load.d.ts +1 -0
- package/v1/examples/concurrency-rr/load.js +54 -0
- package/v1/examples/concurrency-rr/run.d.ts +1 -0
- package/v1/examples/concurrency-rr/run.js +39 -0
- package/v1/examples/concurrency-rr/worker.d.ts +1 -0
- package/v1/examples/concurrency-rr/worker.js +24 -0
- package/v1/examples/concurrency-rr/workflow.d.ts +11 -0
- package/v1/examples/concurrency-rr/workflow.js +35 -0
- package/v1/examples/dag/run.d.ts +1 -0
- package/v1/examples/dag/run.js +24 -0
- package/v1/examples/dag/worker.d.ts +1 -0
- package/v1/examples/dag/worker.js +24 -0
- package/v1/examples/dag/workflow.d.ts +11 -0
- package/v1/examples/dag/workflow.js +35 -0
- package/v1/examples/deep/run.d.ts +1 -0
- package/v1/examples/deep/run.js +28 -0
- package/v1/examples/deep/worker.d.ts +1 -0
- package/v1/examples/deep/worker.js +25 -0
- package/v1/examples/deep/workflow.d.ts +18 -0
- package/v1/examples/deep/workflow.js +110 -0
- package/v1/examples/legacy/run.d.ts +1 -0
- package/v1/examples/legacy/run.js +25 -0
- package/v1/examples/legacy/worker.d.ts +1 -0
- package/v1/examples/legacy/worker.js +24 -0
- package/v1/examples/legacy/workflow.d.ts +2 -0
- package/v1/examples/legacy/workflow.js +36 -0
- package/v1/examples/on_event/event.d.ts +1 -0
- package/v1/examples/on_event/event.js +25 -0
- package/v1/examples/on_event/worker.d.ts +1 -0
- package/v1/examples/on_event/worker.js +24 -0
- package/v1/examples/on_event/workflow.d.ts +17 -0
- package/v1/examples/on_event/workflow.js +33 -0
- package/v1/examples/simple/cron.d.ts +1 -0
- package/v1/examples/simple/cron.js +26 -0
- package/v1/examples/simple/delay.d.ts +1 -0
- package/v1/examples/simple/delay.js +27 -0
- package/v1/examples/simple/run.d.ts +1 -0
- package/v1/examples/simple/run.js +24 -0
- package/v1/examples/simple/schedule.d.ts +1 -0
- package/v1/examples/simple/schedule.js +27 -0
- package/v1/examples/simple/worker.d.ts +1 -0
- package/v1/examples/simple/worker.js +24 -0
- package/v1/examples/simple/workflow.d.ts +5 -0
- package/v1/examples/simple/workflow.js +15 -0
- package/v1/index.d.ts +0 -0
- package/v1/index.js +1 -0
- package/v1/task.d.ts +51 -0
- package/v1/task.js +2 -0
- package/v1/workflow.d.ts +152 -0
- package/v1/workflow.js +145 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +3 -0
|
@@ -0,0 +1,125 @@
|
|
|
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.Worker = void 0;
|
|
13
|
+
exports.toV0Workflow = toV0Workflow;
|
|
14
|
+
const workflow_1 = require("../workflow");
|
|
15
|
+
/**
|
|
16
|
+
* HatchetWorker class for workflow execution runtime
|
|
17
|
+
*/
|
|
18
|
+
class Worker {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new HatchetWorker instance
|
|
21
|
+
* @param v0 - The V0 worker implementation
|
|
22
|
+
*/
|
|
23
|
+
constructor(v0) {
|
|
24
|
+
this.v0 = v0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates and initializes a new HatchetWorker
|
|
28
|
+
* @param v0 - The HatchetClient instance
|
|
29
|
+
* @param options - Worker creation options
|
|
30
|
+
* @returns A new HatchetWorker instance
|
|
31
|
+
*/
|
|
32
|
+
static create(v0, name, options) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const v0worker = yield v0.worker(name, Object.assign(Object.assign({}, options), { maxRuns: options.slots || options.maxRuns }));
|
|
35
|
+
const worker = new Worker(v0worker);
|
|
36
|
+
yield worker.registerWorkflows(options.workflows);
|
|
37
|
+
return worker;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registers workflows with the worker
|
|
42
|
+
* @param workflows - Array of workflows to register
|
|
43
|
+
* @returns Array of registered workflow promises
|
|
44
|
+
*/
|
|
45
|
+
registerWorkflows(workflows) {
|
|
46
|
+
return workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => {
|
|
47
|
+
return this.v0.registerWorkflow(toV0Workflow(wf));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Registers a single workflow with the worker
|
|
52
|
+
* @param workflow - The workflow to register
|
|
53
|
+
* @returns A promise that resolves when the workflow is registered
|
|
54
|
+
* @deprecated use registerWorkflows instead
|
|
55
|
+
*/
|
|
56
|
+
registerWorkflow(workflow) {
|
|
57
|
+
return this.registerWorkflows([workflow]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Starts the worker
|
|
61
|
+
* @returns Promise that resolves when the worker is stopped or killed
|
|
62
|
+
*/
|
|
63
|
+
start() {
|
|
64
|
+
return this.v0.start();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Stops the worker
|
|
68
|
+
* @returns Promise that resolves when the worker stops
|
|
69
|
+
*/
|
|
70
|
+
stop() {
|
|
71
|
+
return this.v0.stop();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Updates or inserts worker labels
|
|
75
|
+
* @param labels - Worker labels to update
|
|
76
|
+
* @returns Promise that resolves when labels are updated
|
|
77
|
+
*/
|
|
78
|
+
upsertLabels(labels) {
|
|
79
|
+
return this.v0.upsertLabels(labels);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the labels for the worker
|
|
83
|
+
* @returns The labels for the worker
|
|
84
|
+
*/
|
|
85
|
+
getLabels() {
|
|
86
|
+
return this.v0.labels;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Register a webhook with the worker
|
|
90
|
+
* @param webhook - The webhook to register
|
|
91
|
+
* @returns A promise that resolves when the webhook is registered
|
|
92
|
+
*/
|
|
93
|
+
registerWebhook(webhook) {
|
|
94
|
+
return this.v0.registerWebhook(webhook);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.Worker = Worker;
|
|
98
|
+
function toV0Workflow(wf) {
|
|
99
|
+
if (wf instanceof workflow_1.Workflow) {
|
|
100
|
+
const { definition } = wf;
|
|
101
|
+
return {
|
|
102
|
+
id: definition.name,
|
|
103
|
+
description: definition.description || '',
|
|
104
|
+
version: definition.version || '',
|
|
105
|
+
sticky: definition.sticky,
|
|
106
|
+
scheduleTimeout: definition.scheduleTimeout,
|
|
107
|
+
on: definition.on,
|
|
108
|
+
concurrency: definition.concurrency,
|
|
109
|
+
steps: definition.tasks.map((task) => {
|
|
110
|
+
var _a;
|
|
111
|
+
return ({
|
|
112
|
+
name: task.name,
|
|
113
|
+
parents: (_a = task.parents) === null || _a === void 0 ? void 0 : _a.map((p) => p.name),
|
|
114
|
+
run: (ctx) => task.fn(ctx.workflowInput(), ctx),
|
|
115
|
+
timeout: task.timeout,
|
|
116
|
+
retries: task.retries,
|
|
117
|
+
rate_limits: task.rateLimits,
|
|
118
|
+
worker_labels: task.workerLabels,
|
|
119
|
+
backoff: task.backoff,
|
|
120
|
+
});
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return wf;
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.parent.run({
|
|
16
|
+
N: 10,
|
|
17
|
+
});
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.log(res.sum.Result);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main()
|
|
24
|
+
.then(() => process.exit(0))
|
|
25
|
+
.catch((error) => {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.error('Error:', error);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const client_1 = require("../client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield client_1.hatchet.worker('child-workflow-worker', {
|
|
17
|
+
workflows: [workflow_1.parent, workflow_1.child],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ChildInput = {
|
|
2
|
+
N: number;
|
|
3
|
+
};
|
|
4
|
+
type ChildOutput = {
|
|
5
|
+
value: {
|
|
6
|
+
Value: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const child: import("../../workflow").Workflow<ChildInput, ChildOutput>;
|
|
10
|
+
type ParentInput = {
|
|
11
|
+
N: number;
|
|
12
|
+
};
|
|
13
|
+
type ParentOutput = {
|
|
14
|
+
sum: {
|
|
15
|
+
Result: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const parent: import("../../workflow").Workflow<ParentInput, ParentOutput>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
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.parent = exports.child = void 0;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
exports.child = client_1.hatchet.workflow({
|
|
15
|
+
name: 'child',
|
|
16
|
+
});
|
|
17
|
+
exports.child.task({
|
|
18
|
+
name: 'value',
|
|
19
|
+
fn: (input) => {
|
|
20
|
+
return {
|
|
21
|
+
Value: input.N,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
exports.parent = client_1.hatchet.workflow({
|
|
26
|
+
name: 'parent',
|
|
27
|
+
});
|
|
28
|
+
exports.parent.task({
|
|
29
|
+
name: 'sum',
|
|
30
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const n = input.N;
|
|
32
|
+
const promises = [];
|
|
33
|
+
// eslint-disable-next-line no-plusplus
|
|
34
|
+
for (let i = 0; i < n; i++) {
|
|
35
|
+
promises.push(ctx.runChild(exports.child, { N: i }));
|
|
36
|
+
}
|
|
37
|
+
const childRes = yield Promise.all(promises);
|
|
38
|
+
const sum = childRes.reduce((acc, curr) => acc + curr.value.Value, 0);
|
|
39
|
+
return {
|
|
40
|
+
Result: sum,
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/* eslint-disable no-plusplus */
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
function generateRandomString(length) {
|
|
16
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
17
|
+
let result = '';
|
|
18
|
+
for (let i = 0; i < length; i++) {
|
|
19
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function main() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const groupCount = 2;
|
|
26
|
+
const runsPerGroup = 20000;
|
|
27
|
+
const BATCH_SIZE = 400;
|
|
28
|
+
const workflowRuns = [];
|
|
29
|
+
for (let i = 0; i < groupCount; i++) {
|
|
30
|
+
for (let j = 0; j < runsPerGroup; j++) {
|
|
31
|
+
workflowRuns.push({
|
|
32
|
+
workflowName: workflow_1.simpleConcurrency.definition.name,
|
|
33
|
+
input: {
|
|
34
|
+
Message: generateRandomString(10),
|
|
35
|
+
GroupKey: `group-${i}`,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Shuffle the workflow runs array
|
|
41
|
+
for (let i = workflowRuns.length - 1; i > 0; i--) {
|
|
42
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
43
|
+
[workflowRuns[i], workflowRuns[j]] = [workflowRuns[j], workflowRuns[i]];
|
|
44
|
+
}
|
|
45
|
+
// Process workflows in batches
|
|
46
|
+
for (let i = 0; i < workflowRuns.length; i += BATCH_SIZE) {
|
|
47
|
+
const batch = workflowRuns.slice(i, i + BATCH_SIZE);
|
|
48
|
+
yield client_1.hatchet.admin.runWorkflows(batch);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (require.main === module) {
|
|
53
|
+
main().then(() => process.exit(0));
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.simpleConcurrency.run([
|
|
16
|
+
{
|
|
17
|
+
Message: 'Hello World',
|
|
18
|
+
GroupKey: 'A',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
Message: 'Goodbye Moon',
|
|
22
|
+
GroupKey: 'A',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
Message: 'Hello World B',
|
|
26
|
+
GroupKey: 'B',
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(res[0]['to-lower'].TransformedMessage);
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(res[1]['to-lower'].TransformedMessage);
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.log(res[2]['to-lower'].TransformedMessage);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (require.main === module) {
|
|
38
|
+
main().then(() => process.exit(0));
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const client_1 = require("../client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield client_1.hatchet.worker('simple-concurrency-worker', {
|
|
17
|
+
workflows: [workflow_1.simpleConcurrency],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type SimpleInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
GroupKey: string;
|
|
4
|
+
};
|
|
5
|
+
type SimpleOutput = {
|
|
6
|
+
'to-lower': {
|
|
7
|
+
TransformedMessage: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const simpleConcurrency: import("../../workflow").Workflow<SimpleInput, SimpleOutput>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
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.simpleConcurrency = void 0;
|
|
13
|
+
const workflow_1 = require("../../../workflow");
|
|
14
|
+
const client_1 = require("../client");
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
16
|
+
setTimeout(resolve, ms);
|
|
17
|
+
});
|
|
18
|
+
exports.simpleConcurrency = client_1.hatchet.workflow({
|
|
19
|
+
name: 'simple-concurrency',
|
|
20
|
+
concurrency: {
|
|
21
|
+
name: 'simple-concurrency',
|
|
22
|
+
maxRuns: 100,
|
|
23
|
+
limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
24
|
+
expression: 'input.GroupKey',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
exports.simpleConcurrency.task({
|
|
28
|
+
name: 'to-lower',
|
|
29
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
yield sleep(Math.floor(Math.random() * (1000 - 200 + 1)) + 200);
|
|
31
|
+
return {
|
|
32
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
33
|
+
};
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.dag.run({
|
|
16
|
+
Message: 'hello world',
|
|
17
|
+
});
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.log(res.reverse.Transformed);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const client_1 = require("../client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield client_1.hatchet.worker('dag-worker', {
|
|
17
|
+
workflows: [workflow_1.dag],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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.dag = void 0;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
exports.dag = client_1.hatchet.workflow({
|
|
15
|
+
name: 'simple',
|
|
16
|
+
});
|
|
17
|
+
const toLower = exports.dag.task({
|
|
18
|
+
name: 'to-lower',
|
|
19
|
+
fn: (input) => {
|
|
20
|
+
return {
|
|
21
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
exports.dag.task({
|
|
26
|
+
name: 'reverse',
|
|
27
|
+
parents: [toLower],
|
|
28
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const lower = yield ctx.parentData(toLower);
|
|
30
|
+
return {
|
|
31
|
+
Original: input.Message,
|
|
32
|
+
Transformed: lower.TransformedMessage.split('').reverse().join(''),
|
|
33
|
+
};
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.parent.run({
|
|
16
|
+
Message: 'hello',
|
|
17
|
+
N: 5,
|
|
18
|
+
});
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.log(res.parent.Sum);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (require.main === module) {
|
|
24
|
+
main()
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
.catch(console.error)
|
|
27
|
+
.finally(() => process.exit(0));
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const client_1 = require("../client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield client_1.hatchet.worker('simple-worker', {
|
|
17
|
+
workflows: [workflow_1.parent, workflow_1.child1, workflow_1.child2, workflow_1.child3, workflow_1.child4, workflow_1.child5],
|
|
18
|
+
slots: 5000,
|
|
19
|
+
});
|
|
20
|
+
yield worker.start();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (require.main === module) {
|
|
24
|
+
main();
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type SimpleInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
N: number;
|
|
4
|
+
};
|
|
5
|
+
type Output = {
|
|
6
|
+
transformer: {
|
|
7
|
+
Sum: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const child1: import("../../workflow").Workflow<SimpleInput, Output>;
|
|
11
|
+
export declare const child2: import("../../workflow").Workflow<SimpleInput, Output>;
|
|
12
|
+
export declare const child3: import("../../workflow").Workflow<SimpleInput, Output>;
|
|
13
|
+
export declare const child4: import("../../workflow").Workflow<SimpleInput, Output>;
|
|
14
|
+
export declare const child5: import("../../workflow").Workflow<SimpleInput, Output>;
|
|
15
|
+
export declare const parent: import("../../workflow").Workflow<SimpleInput, {
|
|
16
|
+
parent: Output["transformer"];
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|