@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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// ❓ Declaring a Child
|
|
3
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -11,32 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
10
|
};
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.parent = exports.child = void 0;
|
|
13
|
+
/* eslint-disable no-plusplus */
|
|
14
|
+
// ❓ Declaring a Child
|
|
14
15
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
exports.child = hatchet_client_1.hatchet.
|
|
16
|
+
exports.child = hatchet_client_1.hatchet.task({
|
|
16
17
|
name: 'child',
|
|
17
|
-
});
|
|
18
|
-
exports.child.task({
|
|
19
|
-
name: 'value',
|
|
20
18
|
fn: (input) => {
|
|
21
19
|
return {
|
|
22
20
|
Value: input.N,
|
|
23
21
|
};
|
|
24
22
|
},
|
|
25
23
|
});
|
|
26
|
-
exports.parent = hatchet_client_1.hatchet.
|
|
24
|
+
exports.parent = hatchet_client_1.hatchet.task({
|
|
27
25
|
name: 'parent',
|
|
28
|
-
});
|
|
29
|
-
exports.parent.task({
|
|
30
|
-
name: 'sum',
|
|
31
26
|
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
27
|
const n = input.N;
|
|
33
28
|
const promises = [];
|
|
34
|
-
// eslint-disable-next-line no-plusplus
|
|
35
29
|
for (let i = 0; i < n; i++) {
|
|
36
30
|
promises.push(ctx.runChild(exports.child, { N: i }));
|
|
37
31
|
}
|
|
38
32
|
const childRes = yield Promise.all(promises);
|
|
39
|
-
const sum = childRes.reduce((acc, curr) => acc + curr.
|
|
33
|
+
const sum = childRes.reduce((acc, curr) => acc + curr.Value, 0);
|
|
40
34
|
return {
|
|
41
35
|
Result: sum,
|
|
42
36
|
};
|
|
@@ -11,9 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.dag = void 0;
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
// ❓ Declaring a DAG Workflow
|
|
15
|
+
// First, we declare the workflow
|
|
14
16
|
exports.dag = hatchet_client_1.hatchet.workflow({
|
|
15
17
|
name: 'simple',
|
|
16
18
|
});
|
|
19
|
+
// Next, we declare the tasks bound to the workflow
|
|
17
20
|
const toLower = exports.dag.task({
|
|
18
21
|
name: 'to-lower',
|
|
19
22
|
fn: (input) => {
|
|
@@ -22,6 +25,7 @@ const toLower = exports.dag.task({
|
|
|
22
25
|
};
|
|
23
26
|
},
|
|
24
27
|
});
|
|
28
|
+
// Next, we declare the tasks bound to the workflow
|
|
25
29
|
exports.dag.task({
|
|
26
30
|
name: 'reverse',
|
|
27
31
|
parents: [toLower],
|
|
@@ -33,3 +37,4 @@ exports.dag.task({
|
|
|
33
37
|
};
|
|
34
38
|
}),
|
|
35
39
|
});
|
|
40
|
+
// !!
|
|
@@ -0,0 +1,40 @@
|
|
|
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 @typescript-eslint/no-unused-vars */
|
|
13
|
+
const conditions_1 = require("../../conditions");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
function main() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
// ❓ Declaring a Durable Task
|
|
18
|
+
const simple = hatchet_client_1.hatchet.durableTask({
|
|
19
|
+
name: 'simple',
|
|
20
|
+
fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
yield ctx.waitFor((0, conditions_1.Or)({
|
|
22
|
+
eventKey: 'user:pay',
|
|
23
|
+
expression: 'input.Status == "PAID"',
|
|
24
|
+
}, {
|
|
25
|
+
sleepFor: '24h',
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
// !!
|
|
33
|
+
// ❓ Running a Task
|
|
34
|
+
const result = yield simple.run({ Message: 'Hello, World!' });
|
|
35
|
+
// !!
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (require.main === module) {
|
|
39
|
+
main();
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simple = void 0;
|
|
4
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
5
|
+
// ❓ Trigger on an event
|
|
6
|
+
exports.simple = hatchet_client_1.hatchet.task({
|
|
7
|
+
name: 'simple',
|
|
8
|
+
onEvents: ['user:created'],
|
|
9
|
+
fn: (input) => {
|
|
10
|
+
// ...
|
|
11
|
+
return {
|
|
12
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
// !!
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simple = void 0;
|
|
4
|
+
const workflows_1 = require("../../../protoc/v1/workflows");
|
|
5
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
6
|
+
// ❓ Process what you can handle
|
|
7
|
+
exports.simple = hatchet_client_1.hatchet.task({
|
|
8
|
+
name: 'simple',
|
|
9
|
+
concurrency: {
|
|
10
|
+
expression: 'input.user_id',
|
|
11
|
+
limitStrategy: workflows_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
12
|
+
maxRuns: 1,
|
|
13
|
+
},
|
|
14
|
+
rateLimits: [
|
|
15
|
+
{
|
|
16
|
+
key: 'api_throttle',
|
|
17
|
+
units: 1,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
fn: (input) => {
|
|
21
|
+
return {
|
|
22
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
// !!
|
|
@@ -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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
// ❓ Declaring a Task
|
|
17
|
+
const simple = hatchet_client_1.hatchet.task({
|
|
18
|
+
name: 'simple',
|
|
19
|
+
fn: (input) => {
|
|
20
|
+
return {
|
|
21
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
// !!
|
|
26
|
+
// ❓ Running a Task
|
|
27
|
+
const result = yield simple.run({ Message: 'Hello, World!' });
|
|
28
|
+
// !!
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (require.main === module) {
|
|
32
|
+
main();
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flow_control_1 = require("./flow-control");
|
|
4
|
+
// ❓ Schedules and Crons
|
|
5
|
+
const tomorrow = new Date(Date.now() + 1000 * 60 * 60 * 24);
|
|
6
|
+
const scheduled = flow_control_1.simple.schedule(tomorrow, {
|
|
7
|
+
Message: 'Hello, World!',
|
|
8
|
+
});
|
|
9
|
+
const cron = flow_control_1.simple.cron('every-day', '0 0 * * *', {
|
|
10
|
+
Message: 'Hello, World!',
|
|
11
|
+
});
|
|
12
|
+
// !!
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simple = void 0;
|
|
4
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
5
|
+
// ❓ Route tasks to workers with matching labels
|
|
6
|
+
exports.simple = hatchet_client_1.hatchet.task({
|
|
7
|
+
name: 'simple',
|
|
8
|
+
desiredWorkerLabels: {
|
|
9
|
+
cpu: {
|
|
10
|
+
value: '2x',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
fn: (input) => {
|
|
14
|
+
return {
|
|
15
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
hatchet_client_1.hatchet.worker('task-routing-worker', {
|
|
20
|
+
workflows: [exports.simple],
|
|
21
|
+
labels: {
|
|
22
|
+
cpu: process.env.CPU_LABEL,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
// !!
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const alwaysFail: import("../..").
|
|
1
|
+
export declare const alwaysFail: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
|
|
@@ -13,19 +13,18 @@ exports.alwaysFail = void 0;
|
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
15
|
// ❓ On Failure Task
|
|
16
|
-
exports.alwaysFail = hatchet_client_1.hatchet.
|
|
16
|
+
exports.alwaysFail = hatchet_client_1.hatchet.task({
|
|
17
17
|
name: 'always-fail',
|
|
18
|
+
// the onFailure function is called when the task fails
|
|
19
|
+
// note: not guaranteed to be called on the same worker
|
|
18
20
|
onFailure: (input, ctx) => {
|
|
19
21
|
console.log('onFailure for run:', ctx.workflowRunId());
|
|
20
22
|
return {
|
|
21
23
|
'on-failure': 'success',
|
|
22
24
|
};
|
|
23
25
|
},
|
|
24
|
-
});
|
|
25
|
-
// !!
|
|
26
|
-
exports.alwaysFail.task({
|
|
27
|
-
name: 'always-fail',
|
|
28
26
|
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
27
|
throw new Error('intentional failure');
|
|
30
28
|
}),
|
|
31
29
|
});
|
|
30
|
+
// !!
|
|
@@ -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
|
+
/* eslint-disable no-console */
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const res = yield workflow_1.retries.run({});
|
|
18
|
+
console.log(res);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log('error', e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
main()
|
|
27
|
+
.catch(console.error)
|
|
28
|
+
.finally(() => process.exit(0));
|
|
29
|
+
}
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
|
|
17
|
+
workflows: [workflow_1.retries],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const retries: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
|
|
2
|
+
export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
|
|
3
|
+
message: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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.withBackoff = exports.retriesWithCount = exports.retries = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
// ❓ Simple Step Retries
|
|
16
|
+
exports.retries = hatchet_client_1.hatchet.task({
|
|
17
|
+
name: 'retries',
|
|
18
|
+
retries: 3,
|
|
19
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
throw new Error('intentional failure');
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
// !!
|
|
24
|
+
// ❓ Step Retries with Count
|
|
25
|
+
exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
26
|
+
name: 'retriesWithCount',
|
|
27
|
+
retries: 3,
|
|
28
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
// ❓ Get the current retry count
|
|
30
|
+
const retryCount = ctx.retryCount();
|
|
31
|
+
console.log(`Retry count: ${retryCount}`);
|
|
32
|
+
if (retryCount < 2) {
|
|
33
|
+
throw new Error('intentional failure');
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
message: 'success',
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
// !!
|
|
41
|
+
// ❓ Step Retries with Backoff
|
|
42
|
+
exports.withBackoff = hatchet_client_1.hatchet.task({
|
|
43
|
+
name: 'withBackoff',
|
|
44
|
+
retries: 3,
|
|
45
|
+
backoff: {
|
|
46
|
+
factor: 2,
|
|
47
|
+
maxSeconds: 10,
|
|
48
|
+
},
|
|
49
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
throw new Error('intentional failure');
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
// !!
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
/* eslint-disable no-console */
|
|
13
|
-
// ❓ Running a
|
|
13
|
+
// ❓ Running a Task with Results
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
// ...
|
|
16
16
|
function main() {
|
|
@@ -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
|
+
/* eslint-disable no-console */
|
|
13
|
+
const workflow_1 = require("../retries/workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const res = yield workflow_1.retries.run({});
|
|
18
|
+
console.log(res);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log('error', e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
main()
|
|
27
|
+
.catch(console.error)
|
|
28
|
+
.finally(() => process.exit(0));
|
|
29
|
+
}
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("../retries/workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
|
|
17
|
+
workflows: [workflow_1.retries],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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.sticky = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const workflows_1 = require("../../../protoc/workflows");
|
|
15
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
+
const workflow_1 = require("../child_workflows/workflow");
|
|
17
|
+
// ❓ Sticky Task
|
|
18
|
+
exports.sticky = hatchet_client_1.hatchet.task({
|
|
19
|
+
name: 'sticky',
|
|
20
|
+
retries: 3,
|
|
21
|
+
sticky: workflows_1.StickyStrategy.SOFT,
|
|
22
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
// specify a child workflow to run on the same worker
|
|
24
|
+
const result = yield ctx.runChild(workflow_1.child, {
|
|
25
|
+
N: 1,
|
|
26
|
+
}, { sticky: true });
|
|
27
|
+
return {
|
|
28
|
+
result,
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
// !!
|
|
@@ -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
|
+
/* eslint-disable no-console */
|
|
13
|
+
// ❓ Running a Task with Results
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
// ...
|
|
16
|
+
function main() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// 👀 Run the workflow with results
|
|
19
|
+
const res = yield workflow_1.cancellation.run({});
|
|
20
|
+
// 👀 Access the results of the workflow
|
|
21
|
+
console.log(res.Completed);
|
|
22
|
+
// !!
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
main()
|
|
27
|
+
.catch(console.error)
|
|
28
|
+
.finally(() => process.exit(0));
|
|
29
|
+
}
|
|
@@ -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,34 @@
|
|
|
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
|
+
executionTimeout: '3s',
|
|
23
|
+
fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { cancelled }) {
|
|
24
|
+
yield (0, sleep_1.default)(10 * 1000);
|
|
25
|
+
if (cancelled) {
|
|
26
|
+
throw new Error('Task was cancelled');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
Completed: true,
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
// !!
|
|
34
|
+
// see ./worker.ts and ./run.ts for how to run the workflow
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type SimpleInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const withTimeouts: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
5
|
+
TransformedMessage: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const refreshTimeout: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
8
|
+
TransformedMessage: string;
|
|
9
|
+
}>;
|