@hatchet-dev/typescript-sdk 1.2.0-alpha.1 → 1.3.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/admin/admin-client.d.ts +3 -1
- package/clients/admin/admin-client.js +1 -1
- package/clients/hatchet-client/features/cron-client.d.ts +3 -0
- package/clients/hatchet-client/features/cron-client.js +2 -0
- package/clients/hatchet-client/features/schedule-client.d.ts +3 -0
- package/clients/hatchet-client/features/schedule-client.js +2 -0
- package/clients/rest/generated/data-contracts.d.ts +193 -167
- package/clients/rest/generated/data-contracts.js +168 -168
- package/clients/worker/worker.js +5 -1
- package/package.json +2 -3
- package/protoc/dispatcher/dispatcher.d.ts +1 -0
- package/protoc/dispatcher/dispatcher.js +17 -1
- package/protoc/v1/workflows.d.ts +6 -1
- package/protoc/v1/workflows.js +60 -4
- package/protoc/workflows/workflows.d.ts +2 -0
- package/protoc/workflows/workflows.js +17 -1
- package/step.d.ts +15 -34
- package/step.js +25 -42
- package/v1/client/client.d.ts +3 -11
- package/v1/client/client.interface.d.ts +0 -2
- package/v1/client/client.js +14 -35
- package/v1/client/worker.js +2 -4
- package/v1/declaration.d.ts +32 -6
- package/v1/declaration.js +55 -64
- package/v1/examples/cancellations/run.js +4 -4
- package/v1/examples/multiple_wf_concurrency/run.js +39 -0
- package/v1/examples/{middleware → multiple_wf_concurrency}/worker.js +3 -8
- package/v1/examples/multiple_wf_concurrency/workflow.d.ts +11 -0
- package/v1/examples/multiple_wf_concurrency/workflow.js +43 -0
- package/v1/examples/priority/run.d.ts +1 -0
- package/v1/examples/priority/run.js +41 -0
- package/v1/examples/priority/worker.d.ts +1 -0
- package/v1/examples/{middleware/run.js → priority/worker.js} +5 -15
- package/v1/examples/priority/workflow.d.ts +8 -0
- package/v1/examples/priority/workflow.js +50 -0
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/task.d.ts +6 -7
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/examples/middleware/hatchet-client.d.ts +0 -2
- package/v1/examples/middleware/hatchet-client.js +0 -32
- package/v1/examples/middleware/workflow.d.ts +0 -9
- package/v1/examples/middleware/workflow.js +0 -37
- package/v1/next/index.d.ts +0 -1
- package/v1/next/index.js +0 -17
- package/v1/next/middleware/middleware.d.ts +0 -27
- package/v1/next/middleware/middleware.js +0 -121
- /package/v1/examples/{middleware → multiple_wf_concurrency}/run.d.ts +0 -0
- /package/v1/examples/{middleware → multiple_wf_concurrency}/worker.d.ts +0 -0
package/v1/declaration.d.ts
CHANGED
|
@@ -3,10 +3,15 @@ import { Context, DurableContext } from '../step';
|
|
|
3
3
|
import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
|
|
4
4
|
import { Workflow as WorkflowV0 } from '../workflow';
|
|
5
5
|
import { IHatchetClient } from './client/client.interface';
|
|
6
|
-
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts,
|
|
6
|
+
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
|
|
7
7
|
import { Duration } from './client/duration';
|
|
8
8
|
import { MetricsClient } from './client/features/metrics';
|
|
9
9
|
import { InputType, OutputType, UnknownInputType, JsonObject } from './types';
|
|
10
|
+
export declare enum Priority {
|
|
11
|
+
LOW = 1,
|
|
12
|
+
MEDIUM = 2,
|
|
13
|
+
HIGH = 3
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* Additional metadata that can be attached to a workflow run.
|
|
12
17
|
*/
|
|
@@ -16,9 +21,15 @@ type AdditionalMetadata = Record<string, string>;
|
|
|
16
21
|
*/
|
|
17
22
|
export type RunOpts = {
|
|
18
23
|
/**
|
|
19
|
-
*
|
|
24
|
+
* (optional) additional metadata to attach to the workflow run.
|
|
20
25
|
*/
|
|
21
26
|
additionalMetadata?: AdditionalMetadata;
|
|
27
|
+
/**
|
|
28
|
+
* (optional) the priority for the workflow run.
|
|
29
|
+
*
|
|
30
|
+
* values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
|
|
31
|
+
*/
|
|
32
|
+
priority?: Priority;
|
|
22
33
|
};
|
|
23
34
|
/**
|
|
24
35
|
* Helper type to safely extract output types from task results
|
|
@@ -58,7 +69,15 @@ export type CreateBaseWorkflowOpts = {
|
|
|
58
69
|
* (optional) event config for the workflow.
|
|
59
70
|
*/
|
|
60
71
|
onEvents?: string[];
|
|
61
|
-
|
|
72
|
+
/**
|
|
73
|
+
* (optional) concurrency config for the workflow.
|
|
74
|
+
*/
|
|
75
|
+
concurrency?: Concurrency | Concurrency[];
|
|
76
|
+
/**
|
|
77
|
+
* (optional) the priority for the workflow.
|
|
78
|
+
* values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
|
|
79
|
+
*/
|
|
80
|
+
defaultPriority?: Priority;
|
|
62
81
|
};
|
|
63
82
|
export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
|
|
64
83
|
export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
|
|
@@ -118,7 +137,7 @@ export type TaskDefaults = {
|
|
|
118
137
|
/**
|
|
119
138
|
* (optional) the concurrency options for the task.
|
|
120
139
|
*/
|
|
121
|
-
concurrency?:
|
|
140
|
+
concurrency?: Concurrency | Concurrency[];
|
|
122
141
|
};
|
|
123
142
|
/**
|
|
124
143
|
* Internal definition of a workflow and its tasks.
|
|
@@ -172,7 +191,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
172
191
|
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
173
192
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
174
193
|
*/
|
|
175
|
-
runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string):
|
|
194
|
+
runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): WorkflowRunRef<O>;
|
|
176
195
|
/**
|
|
177
196
|
* @alias run
|
|
178
197
|
* Triggers a workflow run and waits for the result.
|
|
@@ -301,9 +320,16 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
|
|
|
301
320
|
export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> extends BaseWorkflowDeclaration<I, O> {
|
|
302
321
|
_standalone_task_name: string;
|
|
303
322
|
constructor(options: CreateTaskWorkflowOpts<I, O>, client?: IHatchetClient);
|
|
304
|
-
runNoWait(input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
|
|
305
323
|
run(input: I, options?: RunOpts): Promise<O>;
|
|
306
324
|
run(input: I[], options?: RunOpts): Promise<O[]>;
|
|
325
|
+
/**
|
|
326
|
+
* Triggers a workflow run without waiting for completion.
|
|
327
|
+
* @param input The input data for the workflow.
|
|
328
|
+
* @param options Optional configuration for this workflow run.
|
|
329
|
+
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
330
|
+
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
331
|
+
*/
|
|
332
|
+
runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
|
|
307
333
|
get taskDef(): CreateWorkflowTaskOpts<any, any>;
|
|
308
334
|
}
|
|
309
335
|
/**
|
package/v1/declaration.js
CHANGED
|
@@ -9,12 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = void 0;
|
|
12
|
+
exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.Priority = void 0;
|
|
13
13
|
exports.CreateTaskWorkflow = CreateTaskWorkflow;
|
|
14
14
|
exports.CreateWorkflow = CreateWorkflow;
|
|
15
15
|
exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
|
|
16
|
-
const middleware_1 = require("./next/middleware/middleware");
|
|
17
16
|
const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
|
|
17
|
+
// eslint-disable-next-line no-shadow
|
|
18
|
+
var Priority;
|
|
19
|
+
(function (Priority) {
|
|
20
|
+
Priority[Priority["LOW"] = 1] = "LOW";
|
|
21
|
+
Priority[Priority["MEDIUM"] = 2] = "MEDIUM";
|
|
22
|
+
Priority[Priority["HIGH"] = 3] = "HIGH";
|
|
23
|
+
})(Priority || (exports.Priority = Priority = {}));
|
|
18
24
|
/**
|
|
19
25
|
* Represents a workflow that can be executed by Hatchet.
|
|
20
26
|
* @template I The input type for the workflow.
|
|
@@ -38,25 +44,14 @@ class BaseWorkflowDeclaration {
|
|
|
38
44
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
39
45
|
*/
|
|
40
46
|
runNoWait(input, options, _standaloneTaskName) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
// Wrap the result method to apply output deserialization
|
|
51
|
-
const originalResult = res.result;
|
|
52
|
-
res.result = () => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
var _a;
|
|
54
|
-
const output = yield originalResult.call(res);
|
|
55
|
-
const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, (_a = this.client) === null || _a === void 0 ? void 0 : _a.middleware);
|
|
56
|
-
return deserializedOutput;
|
|
57
|
-
});
|
|
58
|
-
return res;
|
|
59
|
-
});
|
|
47
|
+
if (!this.client) {
|
|
48
|
+
throw UNBOUND_ERR;
|
|
49
|
+
}
|
|
50
|
+
const res = this.client._v0.admin.runWorkflow(this.name, input, options);
|
|
51
|
+
if (_standaloneTaskName) {
|
|
52
|
+
res._standalone_task_name = _standaloneTaskName;
|
|
53
|
+
}
|
|
54
|
+
return res;
|
|
60
55
|
}
|
|
61
56
|
runAndWait(input, options, _standaloneTaskName) {
|
|
62
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -75,16 +70,32 @@ class BaseWorkflowDeclaration {
|
|
|
75
70
|
throw UNBOUND_ERR;
|
|
76
71
|
}
|
|
77
72
|
if (Array.isArray(input)) {
|
|
78
|
-
|
|
73
|
+
let resp = [];
|
|
74
|
+
for (let i = 0; i < input.length; i += 500) {
|
|
75
|
+
const batch = input.slice(i, i + 500);
|
|
76
|
+
const batchResp = yield this.client._v0.admin.runWorkflows(batch.map((inp) => ({
|
|
77
|
+
workflowName: this.definition.name,
|
|
78
|
+
input: inp,
|
|
79
|
+
options,
|
|
80
|
+
})));
|
|
81
|
+
resp = resp.concat(batchResp);
|
|
82
|
+
}
|
|
83
|
+
const res = [];
|
|
84
|
+
resp.forEach((ref, index) => {
|
|
85
|
+
const wf = input[index].workflow;
|
|
86
|
+
if (wf instanceof TaskWorkflowDeclaration) {
|
|
87
|
+
// eslint-disable-next-line no-param-reassign
|
|
88
|
+
ref._standalone_task_name = wf._standalone_task_name;
|
|
89
|
+
}
|
|
90
|
+
res.push(ref.result());
|
|
91
|
+
});
|
|
92
|
+
return Promise.all(res);
|
|
79
93
|
}
|
|
80
|
-
const
|
|
81
|
-
const res = this.client._v0.admin.runWorkflow(this.name, serializedInput, options);
|
|
94
|
+
const res = this.client._v0.admin.runWorkflow(this.definition.name, input, options);
|
|
82
95
|
if (_standaloneTaskName) {
|
|
83
96
|
res._standalone_task_name = _standaloneTaskName;
|
|
84
97
|
}
|
|
85
|
-
|
|
86
|
-
const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.client.middleware);
|
|
87
|
-
return deserializedOutput;
|
|
98
|
+
return res.result();
|
|
88
99
|
});
|
|
89
100
|
}
|
|
90
101
|
/**
|
|
@@ -100,11 +111,7 @@ class BaseWorkflowDeclaration {
|
|
|
100
111
|
if (!this.client) {
|
|
101
112
|
throw UNBOUND_ERR;
|
|
102
113
|
}
|
|
103
|
-
const scheduled = this.client._v0.schedule.create(this.definition.name, {
|
|
104
|
-
triggerAt: enqueueAt,
|
|
105
|
-
input: input,
|
|
106
|
-
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
107
|
-
});
|
|
114
|
+
const scheduled = this.client._v0.schedule.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, options));
|
|
108
115
|
return scheduled;
|
|
109
116
|
});
|
|
110
117
|
}
|
|
@@ -137,12 +144,7 @@ class BaseWorkflowDeclaration {
|
|
|
137
144
|
if (!this.client) {
|
|
138
145
|
throw UNBOUND_ERR;
|
|
139
146
|
}
|
|
140
|
-
const cronDef = this.client._v0.cron.create(this.definition.name, {
|
|
141
|
-
expression,
|
|
142
|
-
input: input,
|
|
143
|
-
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
144
|
-
name,
|
|
145
|
-
});
|
|
147
|
+
const cronDef = this.client._v0.cron.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, options), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
|
|
146
148
|
return cronDef;
|
|
147
149
|
});
|
|
148
150
|
}
|
|
@@ -304,37 +306,26 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
304
306
|
this._standalone_task_name = options.name;
|
|
305
307
|
this.definition._tasks.push(Object.assign({}, options));
|
|
306
308
|
}
|
|
307
|
-
|
|
309
|
+
run(input, options) {
|
|
308
310
|
const _super = Object.create(null, {
|
|
309
|
-
|
|
311
|
+
run: { get: () => super.run }
|
|
310
312
|
});
|
|
311
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
-
|
|
313
|
-
throw UNBOUND_ERR;
|
|
314
|
-
}
|
|
315
|
-
const res = yield _super.runNoWait.call(this, input, options, this._standalone_task_name);
|
|
316
|
-
// Wrap the result method to apply output deserialization
|
|
317
|
-
const originalResult = res.result;
|
|
318
|
-
res.result = () => __awaiter(this, void 0, void 0, function* () {
|
|
319
|
-
var _a;
|
|
320
|
-
const output = yield originalResult.call(res);
|
|
321
|
-
const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, (_a = this.client) === null || _a === void 0 ? void 0 : _a.middleware);
|
|
322
|
-
return deserializedOutput;
|
|
323
|
-
});
|
|
324
|
-
return res;
|
|
314
|
+
return (yield _super.run.call(this, input, options, this._standalone_task_name));
|
|
325
315
|
});
|
|
326
316
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
317
|
+
/**
|
|
318
|
+
* Triggers a workflow run without waiting for completion.
|
|
319
|
+
* @param input The input data for the workflow.
|
|
320
|
+
* @param options Optional configuration for this workflow run.
|
|
321
|
+
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
322
|
+
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
323
|
+
*/
|
|
324
|
+
runNoWait(input, options) {
|
|
325
|
+
if (!this.client) {
|
|
326
|
+
throw UNBOUND_ERR;
|
|
327
|
+
}
|
|
328
|
+
return super.runNoWait(input, options, this._standalone_task_name);
|
|
338
329
|
}
|
|
339
330
|
get taskDef() {
|
|
340
331
|
return this.definition._tasks[0];
|
|
@@ -20,8 +20,8 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
20
20
|
// ...
|
|
21
21
|
function main() {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const run =
|
|
24
|
-
const run1 =
|
|
23
|
+
const run = workflow_1.cancellation.runNoWait({});
|
|
24
|
+
const run1 = workflow_1.cancellation.runNoWait({});
|
|
25
25
|
yield (0, sleep_1.default)(1000);
|
|
26
26
|
yield run.cancel();
|
|
27
27
|
const res = yield run.output;
|
|
@@ -32,8 +32,8 @@ function main() {
|
|
|
32
32
|
yield run.replay();
|
|
33
33
|
const resReplay = yield run.output;
|
|
34
34
|
console.log(resReplay);
|
|
35
|
-
const run2 =
|
|
36
|
-
const run4 =
|
|
35
|
+
const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
|
|
36
|
+
const run4 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
|
|
37
37
|
yield (0, sleep_1.default)(1000);
|
|
38
38
|
yield hatchet_client_1.hatchet.runs.cancel({
|
|
39
39
|
filters: {
|
|
@@ -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.multiConcurrency.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
|
+
}
|
|
@@ -9,16 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
const hatchet_client_1 = require("./hatchet-client");
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
13
|
const workflow_1 = require("./workflow");
|
|
15
14
|
function main() {
|
|
16
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const worker = yield hatchet_client_1.hatchet.worker('
|
|
18
|
-
|
|
19
|
-
workflows: [workflow_1.withMiddleware],
|
|
20
|
-
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
21
|
-
slots: 100,
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('simple-concurrency-worker', {
|
|
17
|
+
workflows: [workflow_1.multiConcurrency],
|
|
22
18
|
});
|
|
23
19
|
yield worker.start();
|
|
24
20
|
});
|
|
@@ -26,4 +22,3 @@ function main() {
|
|
|
26
22
|
if (require.main === module) {
|
|
27
23
|
main();
|
|
28
24
|
}
|
|
29
|
-
// !!
|
|
@@ -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 multiConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
11
|
+
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.multiConcurrency = void 0;
|
|
13
|
+
const workflow_1 = require("../../../workflow");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
16
|
+
setTimeout(resolve, ms);
|
|
17
|
+
});
|
|
18
|
+
// ❓ Concurrency Strategy With Key
|
|
19
|
+
exports.multiConcurrency = hatchet_client_1.hatchet.workflow({
|
|
20
|
+
name: 'simple-concurrency',
|
|
21
|
+
concurrency: [
|
|
22
|
+
{
|
|
23
|
+
maxRuns: 1,
|
|
24
|
+
limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
25
|
+
expression: 'input.GroupKey',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
maxRuns: 1,
|
|
29
|
+
limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
30
|
+
expression: 'input.UserId',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
// !!
|
|
35
|
+
exports.multiConcurrency.task({
|
|
36
|
+
name: 'to-lower',
|
|
37
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
yield sleep(Math.floor(Math.random() * (1000 - 200 + 1)) + 200);
|
|
39
|
+
return {
|
|
40
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
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 v1_1 = require("../..");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
function main() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
console.log('running priority workflow');
|
|
19
|
+
// ❓ Run a Task with a Priority
|
|
20
|
+
const run = workflow_1.priority.run(new Date(Date.now() + 60 * 60 * 1000), { priority: v1_1.Priority.HIGH });
|
|
21
|
+
// !!
|
|
22
|
+
// ❓ Schedule and cron
|
|
23
|
+
const scheduled = workflow_1.priority.schedule(new Date(Date.now() + 60 * 60 * 1000), {}, { priority: v1_1.Priority.HIGH });
|
|
24
|
+
const delayed = workflow_1.priority.delay(60 * 60 * 1000, {}, { priority: v1_1.Priority.HIGH });
|
|
25
|
+
const cron = workflow_1.priority.cron(`daily-cron-${Math.random()}`, '0 0 * * *', {}, { priority: v1_1.Priority.HIGH });
|
|
26
|
+
// !!
|
|
27
|
+
const [scheduledResult, delayedResult] = yield Promise.all([scheduled, delayed]);
|
|
28
|
+
console.log('scheduledResult', scheduledResult);
|
|
29
|
+
console.log('delayedResult', delayedResult);
|
|
30
|
+
// !!
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.log('error', e);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (require.main === module) {
|
|
38
|
+
main()
|
|
39
|
+
.catch(console.error)
|
|
40
|
+
.finally(() => process.exit(0));
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,26 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
13
|
const workflow_1 = require("./workflow");
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Message: 'HeLlO WoRlD',
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('priority-worker', {
|
|
17
|
+
workflows: [...workflow_1.priorityTasks],
|
|
19
18
|
});
|
|
20
|
-
|
|
21
|
-
console.log(res);
|
|
22
|
-
// !!
|
|
19
|
+
yield worker.start();
|
|
23
20
|
});
|
|
24
21
|
}
|
|
25
22
|
if (require.main === module) {
|
|
26
|
-
main()
|
|
27
|
-
.then(() => {
|
|
28
|
-
process.exit(0);
|
|
29
|
-
})
|
|
30
|
-
.catch((err) => {
|
|
31
|
-
console.error(err);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
});
|
|
23
|
+
main();
|
|
34
24
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Priority } from '../..';
|
|
2
|
+
export declare const priority: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
3
|
+
priority: Priority | undefined;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const priorityWf: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
6
|
+
export declare const priorityTasks: (import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}> | import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
7
|
+
priority: Priority | undefined;
|
|
8
|
+
}>)[];
|
|
@@ -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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.priorityTasks = exports.priorityWf = exports.priority = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const v1_1 = require("../..");
|
|
15
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
+
// ❓ Simple Task Priority
|
|
17
|
+
exports.priority = hatchet_client_1.hatchet.task({
|
|
18
|
+
name: 'priority',
|
|
19
|
+
defaultPriority: v1_1.Priority.MEDIUM,
|
|
20
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return {
|
|
22
|
+
priority: ctx.priority(),
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
// !!
|
|
27
|
+
// ❓ Task Priority in a Workflow
|
|
28
|
+
exports.priorityWf = hatchet_client_1.hatchet.workflow({
|
|
29
|
+
name: 'priorityWf',
|
|
30
|
+
defaultPriority: v1_1.Priority.LOW,
|
|
31
|
+
});
|
|
32
|
+
// !!
|
|
33
|
+
exports.priorityWf.task({
|
|
34
|
+
name: 'child-medium',
|
|
35
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
return {
|
|
37
|
+
priority: ctx.priority(),
|
|
38
|
+
};
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
exports.priorityWf.task({
|
|
42
|
+
name: 'child-high',
|
|
43
|
+
// will inherit the default priority from the workflow
|
|
44
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
return {
|
|
46
|
+
priority: ctx.priority(),
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
exports.priorityTasks = [exports.priority, exports.priorityWf];
|
package/v1/index.d.ts
CHANGED
package/v1/index.js
CHANGED
package/v1/task.d.ts
CHANGED
|
@@ -3,11 +3,10 @@ import { Context, CreateStep, DurableContext } from '../step';
|
|
|
3
3
|
import { Conditions } from './conditions';
|
|
4
4
|
import { Duration } from './client/duration';
|
|
5
5
|
import { InputType, OutputType, UnknownInputType } from './types';
|
|
6
|
-
import { Middleware } from './next/middleware/middleware';
|
|
7
6
|
/**
|
|
8
7
|
* Options for configuring the concurrency for a task.
|
|
9
8
|
*/
|
|
10
|
-
export type
|
|
9
|
+
export type Concurrency = {
|
|
11
10
|
/**
|
|
12
11
|
* required the CEL expression to use for concurrency
|
|
13
12
|
*
|
|
@@ -30,6 +29,10 @@ export type TaskConcurrency = {
|
|
|
30
29
|
*/
|
|
31
30
|
limitStrategy?: ConcurrencyLimitStrategy;
|
|
32
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated use Concurrency instead
|
|
34
|
+
*/
|
|
35
|
+
export type TaskConcurrency = Concurrency;
|
|
33
36
|
export declare class NonRetryableError extends Error {
|
|
34
37
|
constructor(message?: string);
|
|
35
38
|
}
|
|
@@ -98,11 +101,7 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
98
101
|
/**
|
|
99
102
|
* (optional) the concurrency options for the task
|
|
100
103
|
*/
|
|
101
|
-
concurrency?:
|
|
102
|
-
/**
|
|
103
|
-
* (optional) the middleware for the task
|
|
104
|
-
*/
|
|
105
|
-
middleware?: Middleware[];
|
|
104
|
+
concurrency?: Concurrency | Concurrency[];
|
|
106
105
|
};
|
|
107
106
|
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
107
|
/**
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.3.0";
|
package/version.js
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hatchet = void 0;
|
|
4
|
-
const client_1 = require("../../client/client");
|
|
5
|
-
class EncodeSerializer {
|
|
6
|
-
deserialize(input) {
|
|
7
|
-
console.log('client-encode-deserialize', input);
|
|
8
|
-
if (input.encoded && typeof input.encoded === 'string') {
|
|
9
|
-
console.warn('WARNING THIS IS NOT REAL ENCRYPTION');
|
|
10
|
-
const decoded = Buffer.from(input.encoded, 'base64').toString('utf-8');
|
|
11
|
-
return JSON.parse(decoded);
|
|
12
|
-
}
|
|
13
|
-
return input;
|
|
14
|
-
}
|
|
15
|
-
serialize(input) {
|
|
16
|
-
console.warn('WARNING THIS IS NOT REAL ENCRYPTION');
|
|
17
|
-
const encoded = Buffer.from(JSON.stringify(input)).toString('base64');
|
|
18
|
-
console.log('client-encode-serialize', input);
|
|
19
|
-
return {
|
|
20
|
-
encoded,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
class EncodeMiddleware {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.input = new EncodeSerializer();
|
|
27
|
-
this.output = new EncodeSerializer();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.hatchet = client_1.HatchetClient.init({
|
|
31
|
-
middleware: [new EncodeMiddleware()],
|
|
32
|
-
});
|