@hatchet-dev/typescript-sdk 1.4.2 → 1.5.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/rest/generated/Api.d.ts +4 -0
- package/examples/affinity-workers.js +4 -4
- package/examples/byo-logger.js +2 -2
- package/examples/crons/cron-worker.js +2 -2
- package/examples/logger.js +2 -2
- package/examples/on-failure.js +4 -4
- package/examples/retries-with-backoff.js +2 -2
- package/examples/sticky-worker.js +4 -4
- package/package.json +1 -1
- package/step.js +2 -2
- package/util/workflow-run-ref.d.ts +2 -2
- package/util/workflow-run-ref.js +6 -7
- package/v1/client/admin.d.ts +2 -0
- package/v1/client/admin.js +6 -2
- package/v1/client/worker/context.js +5 -4
- package/v1/declaration.js +3 -3
- package/v1/examples/cancellations/run.js +1 -1
- package/v1/examples/cancellations/worker.js +1 -1
- package/v1/examples/cancellations/workflow.js +2 -2
- package/v1/examples/child_workflows/workflow.js +1 -1
- package/v1/examples/concurrency-rr/workflow.js +2 -2
- package/v1/examples/dag/interface-workflow.js +1 -1
- package/v1/examples/dag/workflow.js +1 -1
- package/v1/examples/dag_match_condition/complex-workflow.js +7 -7
- package/v1/examples/durable-event/workflow.js +2 -2
- package/v1/examples/durable-sleep/workflow.js +1 -1
- package/v1/examples/hatchet-client.d.ts +1 -1
- package/v1/examples/hatchet-client.js +2 -2
- package/v1/examples/landing_page/durable-excution.js +2 -2
- package/v1/examples/landing_page/event-signaling.js +1 -1
- package/v1/examples/landing_page/flow-control.js +1 -1
- package/v1/examples/landing_page/queues.js +2 -2
- package/v1/examples/landing_page/scheduling.js +1 -1
- package/v1/examples/landing_page/task-routing.js +1 -1
- package/v1/examples/migration-guides/mergent.js +5 -5
- package/v1/examples/multiple_wf_concurrency/workflow.js +1 -1
- package/v1/examples/non_retryable/workflow.js +1 -1
- package/v1/examples/on_cron/workflow.js +1 -1
- package/v1/examples/on_event/event.js +1 -1
- package/v1/examples/on_event/workflow.js +1 -1
- package/v1/examples/on_failure/workflow.js +1 -1
- package/v1/examples/on_success/workflow.js +1 -1
- package/v1/examples/priority/run.js +2 -2
- package/v1/examples/priority/workflow.js +2 -2
- package/v1/examples/quickstart/hatchet-client.d.ts +2 -0
- package/v1/examples/quickstart/hatchet-client.js +9 -0
- package/v1/examples/quickstart/run.d.ts +1 -0
- package/v1/examples/quickstart/run.js +25 -0
- package/v1/examples/quickstart/worker.d.ts +1 -0
- package/v1/examples/quickstart/worker.js +25 -0
- package/v1/examples/quickstart/workflows/first-task.d.ts +8 -0
- package/v1/examples/quickstart/workflows/first-task.js +12 -0
- package/v1/examples/rate_limit/workflow.js +3 -3
- package/v1/examples/retries/workflow.js +4 -4
- package/v1/examples/simple/bulk.js +2 -2
- package/v1/examples/simple/client-run.js +1 -1
- package/v1/examples/simple/cron.js +3 -3
- package/v1/examples/simple/enqueue.js +2 -2
- package/v1/examples/simple/run.js +7 -3
- package/v1/examples/simple/schedule.js +9 -1
- package/v1/examples/simple/stub-workflow.js +1 -1
- package/v1/examples/simple/worker.js +1 -1
- package/v1/examples/simple/workflow-with-child.d.ts +5 -1
- package/v1/examples/simple/workflow-with-child.js +18 -5
- package/v1/examples/simple/workflow.js +24 -3
- package/v1/examples/sticky/workflow.js +1 -1
- package/v1/examples/timeouts/run.js +1 -1
- package/v1/examples/timeouts/worker.js +1 -1
- package/v1/examples/timeouts/workflow.js +1 -1
- package/v1/examples/with_timeouts/workflow.js +3 -3
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -16,7 +16,7 @@ function processImage(imageUrl, filters) {
|
|
|
16
16
|
// Do some image processing
|
|
17
17
|
return Promise.resolve({ url: imageUrl, size: 100, format: 'png' });
|
|
18
18
|
}
|
|
19
|
-
//
|
|
19
|
+
// > Before (Mergent)
|
|
20
20
|
function processImageTask(req) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
const { imageUrl, filters } = req.body;
|
|
@@ -52,7 +52,7 @@ exports.imageProcessor = hatchet_client_1.hatchet.task({
|
|
|
52
52
|
// !!
|
|
53
53
|
function run() {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
//
|
|
55
|
+
// > Running a task (Mergent)
|
|
56
56
|
const options = {
|
|
57
57
|
method: 'POST',
|
|
58
58
|
headers: { Authorization: 'Bearer <token>', 'Content-Type': 'application/json' },
|
|
@@ -71,7 +71,7 @@ function run() {
|
|
|
71
71
|
.then((response) => console.log(response))
|
|
72
72
|
.catch((err) => console.error(err));
|
|
73
73
|
// !!
|
|
74
|
-
//
|
|
74
|
+
// > Running a task (Hatchet)
|
|
75
75
|
const result = yield exports.imageProcessor.run({
|
|
76
76
|
imageUrl: 'https://example.com/image.png',
|
|
77
77
|
filters: ['blur'],
|
|
@@ -83,7 +83,7 @@ function run() {
|
|
|
83
83
|
}
|
|
84
84
|
function schedule() {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
//
|
|
86
|
+
// > Scheduling tasks (Mergent)
|
|
87
87
|
const options = {
|
|
88
88
|
// same options as before
|
|
89
89
|
body: JSON.stringify({
|
|
@@ -92,7 +92,7 @@ function schedule() {
|
|
|
92
92
|
}),
|
|
93
93
|
};
|
|
94
94
|
// !!
|
|
95
|
-
//
|
|
95
|
+
// > Scheduling tasks (Hatchet)
|
|
96
96
|
// Schedule the task to run at a specific time
|
|
97
97
|
const runAt = new Date(Date.now() + 1000 * 60 * 60 * 24);
|
|
98
98
|
exports.imageProcessor.schedule(runAt, {
|
|
@@ -15,7 +15,7 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
15
15
|
const sleep = (ms) => new Promise((resolve) => {
|
|
16
16
|
setTimeout(resolve, ms);
|
|
17
17
|
});
|
|
18
|
-
//
|
|
18
|
+
// > Concurrency Strategy With Key
|
|
19
19
|
exports.multiConcurrency = hatchet_client_1.hatchet.workflow({
|
|
20
20
|
name: 'simple-concurrency',
|
|
21
21
|
concurrency: [
|
|
@@ -6,7 +6,7 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
6
6
|
exports.nonRetryableWorkflow = hatchet_client_1.hatchet.workflow({
|
|
7
7
|
name: 'no-retry-workflow',
|
|
8
8
|
});
|
|
9
|
-
//
|
|
9
|
+
// > Non-retrying task
|
|
10
10
|
const shouldNotRetry = exports.nonRetryableWorkflow.task({
|
|
11
11
|
name: 'should-not-retry',
|
|
12
12
|
fn: () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.onCron = void 0;
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
|
-
//
|
|
5
|
+
// > Run Workflow on Cron
|
|
6
6
|
exports.onCron = hatchet_client_1.hatchet.workflow({
|
|
7
7
|
name: 'on-cron-workflow',
|
|
8
8
|
on: {
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const hatchet_client_1 = require("../hatchet-client");
|
|
13
13
|
function main() {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
//
|
|
15
|
+
// > Pushing an Event
|
|
16
16
|
const res = yield hatchet_client_1.hatchet.events.push('simple-event:create', {
|
|
17
17
|
Message: 'hello',
|
|
18
18
|
});
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.upper = exports.lower = exports.SIMPLE_EVENT = void 0;
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
5
|
exports.SIMPLE_EVENT = 'simple-event:create';
|
|
6
|
-
//
|
|
6
|
+
// > Run workflow on event
|
|
7
7
|
exports.lower = hatchet_client_1.hatchet.workflow({
|
|
8
8
|
name: 'lower',
|
|
9
9
|
// 👀 Declare the event that will trigger the workflow
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.failureWorkflow = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
//
|
|
15
|
+
// > On Failure Task
|
|
16
16
|
exports.failureWorkflow = hatchet_client_1.hatchet.workflow({
|
|
17
17
|
name: 'always-fail',
|
|
18
18
|
});
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.onSuccessDag = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
//
|
|
15
|
+
// > On Success DAG
|
|
16
16
|
exports.onSuccessDag = hatchet_client_1.hatchet.workflow({
|
|
17
17
|
name: 'on-success-dag',
|
|
18
18
|
});
|
|
@@ -16,10 +16,10 @@ function main() {
|
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
try {
|
|
18
18
|
console.log('running priority workflow');
|
|
19
|
-
//
|
|
19
|
+
// > Run a Task with a Priority
|
|
20
20
|
const run = workflow_1.priority.run(new Date(Date.now() + 60 * 60 * 1000), { priority: v1_1.Priority.HIGH });
|
|
21
21
|
// !!
|
|
22
|
-
//
|
|
22
|
+
// > Schedule and cron
|
|
23
23
|
const scheduled = workflow_1.priority.schedule(new Date(Date.now() + 60 * 60 * 1000), {}, { priority: v1_1.Priority.HIGH });
|
|
24
24
|
const delayed = workflow_1.priority.delay(60 * 60 * 1000, {}, { priority: v1_1.Priority.HIGH });
|
|
25
25
|
const cron = workflow_1.priority.cron(`daily-cron-${Math.random()}`, '0 0 * * *', {}, { priority: v1_1.Priority.HIGH });
|
|
@@ -13,7 +13,7 @@ exports.priorityTasks = exports.priorityWf = exports.priority = void 0;
|
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const v1_1 = require("../..");
|
|
15
15
|
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
-
//
|
|
16
|
+
// > Simple Task Priority
|
|
17
17
|
exports.priority = hatchet_client_1.hatchet.task({
|
|
18
18
|
name: 'priority',
|
|
19
19
|
defaultPriority: v1_1.Priority.MEDIUM,
|
|
@@ -24,7 +24,7 @@ exports.priority = hatchet_client_1.hatchet.task({
|
|
|
24
24
|
}),
|
|
25
25
|
});
|
|
26
26
|
// !!
|
|
27
|
-
//
|
|
27
|
+
// > Task Priority in a Workflow
|
|
28
28
|
exports.priorityWf = hatchet_client_1.hatchet.workflow({
|
|
29
29
|
name: 'priorityWf',
|
|
30
30
|
defaultPriority: v1_1.Priority.LOW,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hatchet = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("../../../sdk"));
|
|
8
|
+
// HH-client 1 Client
|
|
9
|
+
exports.hatchet = sdk_1.default.init();
|
|
@@ -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 first_task_1 = require("./workflows/first-task");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield first_task_1.firstTask.run({
|
|
16
|
+
Message: 'Hello World!',
|
|
17
|
+
});
|
|
18
|
+
console.log('Finished running task, and got the transformed message! The transformed message is:', res.TransformedMessage);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (require.main === module) {
|
|
22
|
+
main()
|
|
23
|
+
.catch(console.error)
|
|
24
|
+
.finally(() => process.exit(0));
|
|
25
|
+
}
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const first_task_1 = require("./workflows/first-task");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('first-worker', {
|
|
17
|
+
workflows: [first_task_1.firstTask],
|
|
18
|
+
slots: 10,
|
|
19
|
+
});
|
|
20
|
+
yield worker.start();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (require.main === module) {
|
|
24
|
+
main();
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.firstTask = void 0;
|
|
4
|
+
const hatchet_client_1 = require("../../hatchet-client");
|
|
5
|
+
exports.firstTask = hatchet_client_1.hatchet.task({
|
|
6
|
+
name: 'first-task',
|
|
7
|
+
fn: (input, ctx) => {
|
|
8
|
+
return {
|
|
9
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const workflows_1 = require("../../../protoc/v1/workflows");
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
|
-
//
|
|
5
|
+
// > Upsert Rate Limit
|
|
6
6
|
hatchet_client_1.hatchet.ratelimits.upsert({
|
|
7
7
|
key: 'api-service-rate-limit',
|
|
8
8
|
limit: 10,
|
|
9
9
|
duration: workflows_1.RateLimitDuration.SECOND,
|
|
10
10
|
});
|
|
11
11
|
// !!
|
|
12
|
-
//
|
|
12
|
+
// > Static
|
|
13
13
|
const RATE_LIMIT_KEY = 'api-service-rate-limit';
|
|
14
14
|
const task1 = hatchet_client_1.hatchet.task({
|
|
15
15
|
name: 'task1',
|
|
@@ -24,7 +24,7 @@ const task1 = hatchet_client_1.hatchet.task({
|
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
// !!
|
|
27
|
-
//
|
|
27
|
+
// > Dynamic
|
|
28
28
|
const task2 = hatchet_client_1.hatchet.task({
|
|
29
29
|
name: 'task2',
|
|
30
30
|
fn: (input) => {
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.withBackoff = exports.retriesWithCount = exports.retries = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
//
|
|
15
|
+
// > Simple Step Retries
|
|
16
16
|
exports.retries = hatchet_client_1.hatchet.task({
|
|
17
17
|
name: 'retries',
|
|
18
18
|
retries: 3,
|
|
@@ -21,12 +21,12 @@ exports.retries = hatchet_client_1.hatchet.task({
|
|
|
21
21
|
}),
|
|
22
22
|
});
|
|
23
23
|
// !!
|
|
24
|
-
//
|
|
24
|
+
// > Retries with Count
|
|
25
25
|
exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
26
26
|
name: 'retriesWithCount',
|
|
27
27
|
retries: 3,
|
|
28
28
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
//
|
|
29
|
+
// > Get the current retry count
|
|
30
30
|
const retryCount = ctx.retryCount();
|
|
31
31
|
console.log(`Retry count: ${retryCount}`);
|
|
32
32
|
if (retryCount < 2) {
|
|
@@ -38,7 +38,7 @@ exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
40
|
// !!
|
|
41
|
-
//
|
|
41
|
+
// > Retries with Backoff
|
|
42
42
|
exports.withBackoff = hatchet_client_1.hatchet.task({
|
|
43
43
|
name: 'withBackoff',
|
|
44
44
|
retries: 10,
|
|
@@ -14,7 +14,7 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
function main() {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
//
|
|
17
|
+
// > Bulk Run a Task
|
|
18
18
|
const res = yield workflow_1.simple.run([
|
|
19
19
|
{
|
|
20
20
|
Message: 'HeLlO WoRlD',
|
|
@@ -27,7 +27,7 @@ function main() {
|
|
|
27
27
|
console.log(res[0].TransformedMessage);
|
|
28
28
|
console.log(res[1].TransformedMessage);
|
|
29
29
|
// !!
|
|
30
|
-
//
|
|
30
|
+
// > Bulk Run Tasks from within a Task
|
|
31
31
|
const parent = hatchet_client_1.hatchet.task({
|
|
32
32
|
name: 'simple',
|
|
33
33
|
fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//
|
|
3
|
+
// > Client Run Methods
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
5
|
hatchet_client_1.hatchet.run('simple', { Message: 'Hello, World!' });
|
|
6
6
|
hatchet_client_1.hatchet.runNoWait('simple', { Message: 'Hello, World!' }, {});
|
|
@@ -13,7 +13,7 @@ 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
|
-
//
|
|
16
|
+
// > Create
|
|
17
17
|
const cron = yield workflow_1.simple.cron('simple-daily', '0 0 * * *', {
|
|
18
18
|
Message: 'hello',
|
|
19
19
|
});
|
|
@@ -22,10 +22,10 @@ function main() {
|
|
|
22
22
|
// !!
|
|
23
23
|
// eslint-disable-next-line no-console
|
|
24
24
|
console.log(cron.metadata.id);
|
|
25
|
-
//
|
|
25
|
+
// > Delete
|
|
26
26
|
yield hatchet_client_1.hatchet.crons.delete(cronId);
|
|
27
27
|
// !!
|
|
28
|
-
//
|
|
28
|
+
// > List
|
|
29
29
|
const crons = yield hatchet_client_1.hatchet.crons.list({
|
|
30
30
|
workflowId: workflow_1.simple.id,
|
|
31
31
|
});
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
/* eslint-disable import/no-duplicates */
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
//
|
|
15
|
+
// > Enqueuing a Workflow (Fire and Forget)
|
|
16
16
|
const workflow_1 = require("./workflow");
|
|
17
17
|
// ...
|
|
18
18
|
function main() {
|
|
@@ -27,7 +27,7 @@ function main() {
|
|
|
27
27
|
// in a database or other persistent storage for later use
|
|
28
28
|
console.log(runId);
|
|
29
29
|
// !!
|
|
30
|
-
//
|
|
30
|
+
// > Subscribing to results
|
|
31
31
|
// the return object of the enqueue method is a WorkflowRunRef which includes a listener for the result of the workflow
|
|
32
32
|
const result = yield run.result();
|
|
33
33
|
console.log(result);
|
|
@@ -15,9 +15,13 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
15
15
|
const workflow_1 = require("./workflow");
|
|
16
16
|
function main() {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
//
|
|
18
|
+
// > Running a Task
|
|
19
19
|
const res = yield workflow_1.simple.run({
|
|
20
20
|
Message: 'HeLlO WoRlD',
|
|
21
|
+
}, {
|
|
22
|
+
additionalMetadata: {
|
|
23
|
+
test: 'test',
|
|
24
|
+
},
|
|
21
25
|
});
|
|
22
26
|
// 👀 Access the results of the Task
|
|
23
27
|
console.log(res.TransformedMessage);
|
|
@@ -26,7 +30,7 @@ function main() {
|
|
|
26
30
|
}
|
|
27
31
|
function extra() {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
//
|
|
33
|
+
// > Running Multiple Tasks
|
|
30
34
|
const res1 = workflow_1.simple.run({
|
|
31
35
|
Message: 'HeLlO WoRlD',
|
|
32
36
|
});
|
|
@@ -37,7 +41,7 @@ function extra() {
|
|
|
37
41
|
console.log(results[0].TransformedMessage);
|
|
38
42
|
console.log(results[1].TransformedMessage);
|
|
39
43
|
// !!
|
|
40
|
-
//
|
|
44
|
+
// > Spawning Tasks from within a Task
|
|
41
45
|
const parent = hatchet_client_1.hatchet.task({
|
|
42
46
|
name: 'parent',
|
|
43
47
|
fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -14,7 +14,7 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
function main() {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
//
|
|
17
|
+
// > Create a Scheduled Run
|
|
18
18
|
const runAt = new Date(new Date().setHours(12, 0, 0, 0) + 24 * 60 * 60 * 1000);
|
|
19
19
|
const scheduled = yield workflow_1.simple.schedule(runAt, {
|
|
20
20
|
Message: 'hello',
|
|
@@ -25,7 +25,15 @@ function main() {
|
|
|
25
25
|
const scheduledRunId = scheduled.metadata.id;
|
|
26
26
|
console.log(scheduledRunId);
|
|
27
27
|
// !!
|
|
28
|
+
// > Delete a Scheduled Run
|
|
28
29
|
yield hatchet_client_1.hatchet.schedules.delete(scheduled);
|
|
30
|
+
// !!
|
|
31
|
+
// > List Scheduled Runs
|
|
32
|
+
const scheduledRuns = yield hatchet_client_1.hatchet.schedules.list({
|
|
33
|
+
workflowId: workflow_1.simple.id,
|
|
34
|
+
});
|
|
35
|
+
console.log(scheduledRuns);
|
|
36
|
+
// !!
|
|
29
37
|
});
|
|
30
38
|
}
|
|
31
39
|
if (require.main === module) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.simple = void 0;
|
|
4
|
-
//
|
|
4
|
+
// > Declaring an External Workflow Reference
|
|
5
5
|
const hatchet_client_1 = require("../hatchet-client");
|
|
6
6
|
// declare the workflow with the same name as the
|
|
7
7
|
// workflow name on the worker
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
//
|
|
12
|
+
// > Declaring a Worker
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
const workflow_with_child_1 = require("./workflow-with-child");
|
|
@@ -4,7 +4,11 @@ export type ChildInput = {
|
|
|
4
4
|
export type ParentInput = {
|
|
5
5
|
Message: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const child: import("../..").
|
|
7
|
+
export declare const child: import("../..").WorkflowDeclaration<ChildInput, {}>;
|
|
8
|
+
export declare const child1: import("../..").CreateWorkflowTaskOpts<ChildInput, {
|
|
9
|
+
TransformedMessage: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const child2: import("../..").CreateWorkflowTaskOpts<ChildInput, {
|
|
8
12
|
TransformedMessage: string;
|
|
9
13
|
}>;
|
|
10
14
|
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
@@ -9,12 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.parent = exports.child = void 0;
|
|
13
|
-
//
|
|
12
|
+
exports.parent = exports.child2 = exports.child1 = exports.child = void 0;
|
|
13
|
+
// > Declaring a Task
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
-
exports.child = hatchet_client_1.hatchet.
|
|
15
|
+
exports.child = hatchet_client_1.hatchet.workflow({
|
|
16
16
|
name: 'child',
|
|
17
|
-
|
|
17
|
+
});
|
|
18
|
+
exports.child1 = exports.child.task({
|
|
19
|
+
name: 'child1',
|
|
20
|
+
fn: (input, ctx) => {
|
|
21
|
+
ctx.log('hello from the child1');
|
|
22
|
+
return {
|
|
23
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
exports.child2 = exports.child.task({
|
|
28
|
+
name: 'child2',
|
|
29
|
+
fn: (input, ctx) => {
|
|
30
|
+
ctx.log('hello from the child2');
|
|
18
31
|
return {
|
|
19
32
|
TransformedMessage: input.Message.toLowerCase(),
|
|
20
33
|
};
|
|
@@ -27,7 +40,7 @@ exports.parent = hatchet_client_1.hatchet.task({
|
|
|
27
40
|
Message: input.Message,
|
|
28
41
|
});
|
|
29
42
|
return {
|
|
30
|
-
TransformedMessage:
|
|
43
|
+
TransformedMessage: 'not implemented',
|
|
31
44
|
};
|
|
32
45
|
}),
|
|
33
46
|
});
|
|
@@ -1,15 +1,36 @@
|
|
|
1
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
|
+
};
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.simple = void 0;
|
|
4
|
-
//
|
|
16
|
+
// > Declaring a Task
|
|
17
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
5
18
|
const hatchet_client_1 = require("../hatchet-client");
|
|
6
19
|
exports.simple = hatchet_client_1.hatchet.task({
|
|
7
20
|
name: 'simple',
|
|
8
|
-
|
|
21
|
+
retries: 3,
|
|
22
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
ctx.log('hello from the workflow');
|
|
24
|
+
yield (0, sleep_1.default)(100);
|
|
25
|
+
ctx.log('goodbye from the workflow');
|
|
26
|
+
yield (0, sleep_1.default)(100);
|
|
27
|
+
if (ctx.retryCount() < 2) {
|
|
28
|
+
throw new Error('test error');
|
|
29
|
+
}
|
|
9
30
|
return {
|
|
10
31
|
TransformedMessage: input.Message.toLowerCase(),
|
|
11
32
|
};
|
|
12
|
-
},
|
|
33
|
+
}),
|
|
13
34
|
});
|
|
14
35
|
// !!
|
|
15
36
|
// see ./worker.ts and ./run.ts for how to run the workflow
|
|
@@ -14,7 +14,7 @@ exports.sticky = void 0;
|
|
|
14
14
|
const workflows_1 = require("../../../protoc/workflows");
|
|
15
15
|
const hatchet_client_1 = require("../hatchet-client");
|
|
16
16
|
const workflow_1 = require("../child_workflows/workflow");
|
|
17
|
-
//
|
|
17
|
+
// > Sticky Task
|
|
18
18
|
exports.sticky = hatchet_client_1.hatchet.task({
|
|
19
19
|
name: 'sticky',
|
|
20
20
|
retries: 3,
|
|
@@ -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
|
-
//
|
|
13
|
+
// > Running a Task with Results
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
// ...
|
|
16
16
|
function main() {
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
//
|
|
12
|
+
// > Declaring a Worker
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
15
|
function main() {
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.cancellation = void 0;
|
|
16
|
-
//
|
|
16
|
+
// > Declaring a Task
|
|
17
17
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
18
|
const hatchet_client_1 = require("../hatchet-client");
|
|
19
19
|
// (optional) Define the input type for the workflow
|
|
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.refreshTimeout = exports.withTimeouts = void 0;
|
|
16
|
-
//
|
|
16
|
+
// > Declaring a Task
|
|
17
17
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
18
|
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
-
//
|
|
19
|
+
// > Execution Timeout
|
|
20
20
|
exports.withTimeouts = hatchet_client_1.hatchet.task({
|
|
21
21
|
name: 'with-timeouts',
|
|
22
22
|
// time the task can wait in the queue before it is cancelled
|
|
@@ -38,7 +38,7 @@ exports.withTimeouts = hatchet_client_1.hatchet.task({
|
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
40
|
// !!
|
|
41
|
-
//
|
|
41
|
+
// > Refresh Timeout
|
|
42
42
|
exports.refreshTimeout = hatchet_client_1.hatchet.task({
|
|
43
43
|
name: 'refresh-timeout',
|
|
44
44
|
executionTimeout: '10s',
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.5.1";
|
package/version.js
CHANGED