@hatchet-dev/typescript-sdk 1.13.1 → 1.14.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/dispatcher/dispatcher-client.d.ts +1 -1
- package/clients/dispatcher/heartbeat/heartbeat-controller.js +13 -1
- package/clients/dispatcher/heartbeat/heartbeat-worker.js +4 -3
- package/clients/event/event-client.d.ts +1 -2
- package/clients/event/event-client.js +2 -2
- package/clients/hatchet-client/client-config.d.ts +15 -5
- package/clients/hatchet-client/client-config.js +3 -0
- package/clients/hatchet-client/hatchet-logger.js +1 -0
- package/clients/hatchet-client/index.d.ts +1 -1
- package/clients/hatchet-client/index.js +1 -1
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +6 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +8 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +9 -2
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +67 -15
- package/clients/listeners/run-listener/child-listener-client.js +1 -0
- package/clients/listeners/run-listener/pooled-child-listener-client.d.ts +10 -2
- package/clients/listeners/run-listener/pooled-child-listener-client.js +63 -7
- package/clients/rest/api.js +10 -2
- package/clients/rest/generated/Api.d.ts +2 -2
- package/clients/rest/generated/data-contracts.d.ts +6 -0
- package/index.d.ts +2 -3
- package/index.js +2 -3
- package/{examples → legacy/examples}/affinity-workers.js +2 -2
- package/{examples → legacy/examples}/bulk-fanout-trigger.js +1 -1
- package/{examples → legacy/examples}/bulk-fanout-worker.js +1 -1
- package/{examples → legacy/examples}/bulk-trigger.js +1 -1
- package/{examples → legacy/examples}/byo-logger.js +1 -1
- package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.js +1 -1
- package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.js +1 -1
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.js +1 -1
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.js +2 -2
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.js +2 -2
- package/{examples → legacy/examples}/crons/cron-worker.d.ts +1 -1
- package/{examples → legacy/examples}/crons/cron-worker.js +1 -1
- package/{examples → legacy/examples}/crons/programatic-crons.js +1 -1
- package/{examples → legacy/examples}/dag-worker.js +1 -1
- package/{examples → legacy/examples}/example-event-with-results.js +2 -2
- package/{examples → legacy/examples}/example-event.js +1 -1
- package/{examples → legacy/examples}/fanout-worker.js +1 -1
- package/{examples → legacy/examples}/logger.js +1 -1
- package/{examples → legacy/examples}/manual-trigger.js +1 -1
- package/{examples → legacy/examples}/multi-workflow.js +1 -1
- package/{examples → legacy/examples}/namespaced-worker.js +1 -1
- package/{examples → legacy/examples}/on-failure.js +1 -1
- package/{examples → legacy/examples}/rate-limit/events.js +1 -1
- package/{examples → legacy/examples}/rate-limit/worker.js +2 -2
- package/{examples → legacy/examples}/retries-with-backoff.js +1 -1
- package/{examples → legacy/examples}/retries-worker.js +1 -1
- package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.js +1 -1
- package/{examples → legacy/examples}/simple-worker.d.ts +1 -1
- package/{examples → legacy/examples}/simple-worker.js +1 -1
- package/{examples → legacy/examples}/sticky-trigger.js +1 -1
- package/{examples → legacy/examples}/sticky-worker-with-check.js +2 -2
- package/{examples → legacy/examples}/sticky-worker.js +2 -2
- package/{examples → legacy/examples}/stream-by-additional-meta.js +2 -2
- package/legacy/legacy-client.d.ts +30 -0
- package/legacy/legacy-client.js +67 -0
- package/legacy/legacy-transformer.d.ts +38 -0
- package/legacy/legacy-transformer.js +181 -0
- package/legacy/step.d.ts +429 -0
- package/legacy/step.js +662 -0
- package/legacy/workflow.d.ts +488 -0
- package/legacy/workflow.js +72 -0
- package/package.json +2 -2
- package/step.d.ts +1 -430
- package/step.js +6 -647
- package/util/abort-error.d.ts +38 -0
- package/util/abort-error.js +58 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +8 -1
- package/util/hatchet-promise/hatchet-promise.js +3 -2
- package/util/logger/index.d.ts +1 -0
- package/util/logger/index.js +1 -0
- package/util/logger/task-run-log.d.ts +3 -0
- package/util/logger/task-run-log.js +20 -0
- package/util/sleep.d.ts +5 -2
- package/util/sleep.js +27 -4
- package/util/workflow-run-ref.d.ts +7 -1
- package/util/workflow-run-ref.js +5 -3
- package/v1/client/admin.d.ts +8 -1
- package/v1/client/admin.js +22 -6
- package/v1/client/client.d.ts +36 -18
- package/v1/client/client.interface.d.ts +9 -2
- package/v1/client/client.js +47 -27
- package/v1/client/features/crons.d.ts +3 -3
- package/v1/client/features/crons.js +2 -2
- package/v1/client/features/schedules.js +2 -2
- package/v1/client/features/workflows.d.ts +5 -5
- package/v1/client/features/workflows.js +7 -8
- package/v1/client/worker/context.d.ts +49 -10
- package/v1/client/worker/context.js +92 -20
- package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +3 -3
- package/v1/client/worker/deprecated/legacy-v1-worker.js +2 -2
- package/v1/client/worker/deprecated/legacy-worker.js +9 -7
- package/v1/client/worker/slot-utils.d.ts +3 -3
- package/v1/client/worker/worker-internal.d.ts +7 -16
- package/v1/client/worker/worker-internal.js +225 -209
- package/v1/client/worker/worker.d.ts +18 -18
- package/v1/client/worker/worker.js +45 -30
- package/v1/declaration.d.ts +28 -7
- package/v1/declaration.js +56 -6
- package/v1/examples/__e2e__/harness.d.ts +19 -0
- package/v1/examples/__e2e__/harness.js +70 -0
- package/v1/examples/affinity/affinity-workers.js +4 -4
- package/v1/examples/bulk_fanout/workflow.d.ts +9 -0
- package/v1/examples/bulk_fanout/workflow.js +34 -0
- package/v1/examples/bulk_operations/workflow.d.ts +3 -0
- package/v1/examples/bulk_operations/workflow.js +44 -0
- package/v1/examples/cancellation/cancellation-workflow.d.ts +2 -0
- package/v1/examples/cancellation/cancellation-workflow.js +69 -0
- package/v1/examples/cancellation/run.js +53 -0
- package/v1/examples/cancellation/worker.d.ts +1 -0
- package/v1/examples/cancellation/worker.js +29 -0
- package/v1/examples/concurrency-types.d.ts +5 -0
- package/v1/examples/concurrency-types.js +2 -0
- package/v1/examples/concurrency_cancel_in_progress/workflow.d.ts +9 -0
- package/v1/examples/concurrency_cancel_in_progress/workflow.js +45 -0
- package/v1/examples/concurrency_cancel_newest/workflow.d.ts +9 -0
- package/v1/examples/concurrency_cancel_newest/workflow.js +45 -0
- package/v1/examples/concurrency_limit_rr/load.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/load.js +54 -0
- package/v1/examples/concurrency_limit_rr/run.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/run.js +39 -0
- package/v1/examples/concurrency_limit_rr/worker.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/worker.js +24 -0
- package/v1/examples/concurrency_limit_rr/workflow.d.ts +12 -0
- package/v1/examples/concurrency_limit_rr/workflow.js +62 -0
- package/v1/examples/concurrency_multiple_keys/workflow.d.ts +12 -0
- package/v1/examples/concurrency_multiple_keys/workflow.js +42 -0
- package/v1/examples/concurrency_workflow_level/workflow.d.ts +13 -0
- package/v1/examples/concurrency_workflow_level/workflow.js +49 -0
- package/v1/examples/conditions/complex-workflow.d.ts +1 -0
- package/v1/examples/conditions/complex-workflow.js +107 -0
- package/v1/examples/conditions/event.d.ts +1 -0
- package/v1/examples/conditions/event.js +28 -0
- package/v1/examples/conditions/run.d.ts +1 -0
- package/v1/examples/conditions/run.js +25 -0
- package/v1/examples/conditions/worker.d.ts +1 -0
- package/v1/examples/conditions/worker.js +24 -0
- package/v1/examples/conditions/workflow.d.ts +11 -0
- package/v1/examples/conditions/workflow.js +41 -0
- package/v1/examples/durable/workflow.d.ts +7 -0
- package/v1/examples/durable/workflow.js +116 -0
- package/v1/examples/durable_event/event.d.ts +1 -0
- package/v1/examples/durable_event/event.js +28 -0
- package/v1/examples/durable_event/run.d.ts +1 -0
- package/v1/examples/durable_event/run.js +30 -0
- package/v1/examples/durable_event/worker.d.ts +1 -0
- package/v1/examples/durable_event/worker.js +24 -0
- package/v1/examples/durable_event/workflow.d.ts +6 -0
- package/v1/examples/durable_event/workflow.js +46 -0
- package/v1/examples/durable_sleep/event.d.ts +1 -0
- package/v1/examples/durable_sleep/event.js +28 -0
- package/v1/examples/durable_sleep/run.d.ts +1 -0
- package/v1/examples/durable_sleep/run.js +30 -0
- package/v1/examples/durable_sleep/worker.d.ts +1 -0
- package/v1/examples/durable_sleep/worker.js +24 -0
- package/v1/examples/durable_sleep/workflow.d.ts +1 -0
- package/v1/examples/durable_sleep/workflow.js +31 -0
- package/v1/examples/e2e-worker.d.ts +1 -0
- package/v1/examples/e2e-worker.js +82 -0
- package/v1/examples/events/event.d.ts +1 -0
- package/v1/examples/events/event.js +53 -0
- package/v1/examples/events/filter.d.ts +1 -0
- package/v1/examples/events/filter.js +32 -0
- package/v1/examples/events/worker.d.ts +1 -0
- package/v1/examples/events/worker.js +24 -0
- package/v1/examples/events/workflow.d.ts +19 -0
- package/v1/examples/events/workflow.js +60 -0
- package/v1/examples/high-memory/workflow-with-child.js +1 -1
- package/v1/examples/logger/byo-logger.d.ts +1 -0
- package/v1/examples/logger/byo-logger.js +73 -0
- package/v1/examples/logger/logger.d.ts +1 -0
- package/v1/examples/logger/logger.js +46 -0
- package/v1/examples/logger/workflow.d.ts +2 -0
- package/v1/examples/logger/workflow.js +38 -0
- package/v1/examples/multiple_wf_concurrency/workflow.js +3 -3
- package/v1/examples/on_failure/workflow.d.ts +1 -0
- package/v1/examples/on_failure/workflow.js +12 -7
- package/v1/examples/priority/workflow.js +1 -1
- package/v1/examples/retries/workflow.js +2 -2
- package/v1/examples/return_exceptions/workflow.d.ts +6 -0
- package/v1/examples/return_exceptions/workflow.js +22 -0
- package/v1/examples/run_details/workflow.d.ts +4 -0
- package/v1/examples/run_details/workflow.js +65 -0
- package/v1/examples/simple/e2e-workflows.d.ts +14 -0
- package/v1/examples/simple/e2e-workflows.js +27 -0
- package/v1/examples/simple/enqueue.js +2 -2
- package/v1/examples/sticky/workflow.js +2 -2
- package/v1/examples/timeout/run.d.ts +1 -0
- package/v1/examples/timeout/run.js +30 -0
- package/v1/examples/timeout/worker.d.ts +1 -0
- package/v1/examples/timeout/worker.js +25 -0
- package/v1/examples/timeout/workflow.d.ts +10 -0
- package/v1/examples/timeout/workflow.js +56 -0
- package/v1/examples/webhooks/workflow.d.ts +5 -0
- package/v1/examples/webhooks/workflow.js +23 -0
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/parent-run-context-vars.d.ts +6 -0
- package/v1/parent-run-context-vars.js +3 -0
- package/v1/task.d.ts +22 -7
- package/v1/task.js +4 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +3 -491
- package/workflow.js +12 -62
- package/clients/hatchet-client/hatchet-client.d.ts +0 -35
- package/clients/hatchet-client/hatchet-client.js +0 -108
- package/clients/worker/handler.d.ts +0 -50
- package/clients/worker/handler.js +0 -214
- package/clients/worker/index.d.ts +0 -1
- package/clients/worker/index.js +0 -17
- package/clients/worker/worker.d.ts +0 -59
- package/clients/worker/worker.js +0 -568
- package/examples/webhooks.js +0 -45
- /package/{examples → legacy/examples}/affinity-workers.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-fanout-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-fanout-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/byo-logger.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.d.ts +0 -0
- /package/{examples → legacy/examples}/crons/programatic-crons.d.ts +0 -0
- /package/{examples → legacy/examples}/dag-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/example-event-with-results.d.ts +0 -0
- /package/{examples → legacy/examples}/example-event.d.ts +0 -0
- /package/{examples → legacy/examples}/fanout-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/logger.d.ts +0 -0
- /package/{examples → legacy/examples}/manual-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/multi-workflow.d.ts +0 -0
- /package/{examples → legacy/examples}/namespaced-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/on-failure.d.ts +0 -0
- /package/{examples → legacy/examples}/rate-limit/events.d.ts +0 -0
- /package/{examples → legacy/examples}/rate-limit/worker.d.ts +0 -0
- /package/{examples → legacy/examples}/retries-with-backoff.d.ts +0 -0
- /package/{examples → legacy/examples}/retries-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-worker-with-check.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/stream-by-additional-meta.d.ts +0 -0
- /package/{examples/webhooks.d.ts → v1/examples/cancellation/run.d.ts} +0 -0
|
@@ -0,0 +1,107 @@
|
|
|
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.taskConditionWorkflow = void 0;
|
|
13
|
+
// > Create a workflow
|
|
14
|
+
const conditions_1 = require("../../conditions");
|
|
15
|
+
const parent_condition_1 = require("../../conditions/parent-condition");
|
|
16
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
17
|
+
exports.taskConditionWorkflow = hatchet_client_1.hatchet.workflow({
|
|
18
|
+
name: 'TaskConditionWorkflow',
|
|
19
|
+
});
|
|
20
|
+
// !!
|
|
21
|
+
// > Add base task
|
|
22
|
+
const start = exports.taskConditionWorkflow.task({
|
|
23
|
+
name: 'start',
|
|
24
|
+
fn: () => {
|
|
25
|
+
return {
|
|
26
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
// !!
|
|
31
|
+
// > Add wait for sleep
|
|
32
|
+
const waitForSleep = exports.taskConditionWorkflow.task({
|
|
33
|
+
name: 'waitForSleep',
|
|
34
|
+
parents: [start],
|
|
35
|
+
waitFor: [new conditions_1.SleepCondition('10s')],
|
|
36
|
+
fn: () => {
|
|
37
|
+
return {
|
|
38
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
// !!
|
|
43
|
+
// > Add skip on event
|
|
44
|
+
const skipOnEvent = exports.taskConditionWorkflow.task({
|
|
45
|
+
name: 'skipOnEvent',
|
|
46
|
+
parents: [start],
|
|
47
|
+
waitFor: [new conditions_1.SleepCondition('10s')],
|
|
48
|
+
skipIf: [new conditions_1.UserEventCondition('skip_on_event:skip', 'true')],
|
|
49
|
+
fn: () => {
|
|
50
|
+
return {
|
|
51
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
// !!
|
|
56
|
+
// > Add branching
|
|
57
|
+
const leftBranch = exports.taskConditionWorkflow.task({
|
|
58
|
+
name: 'leftBranch',
|
|
59
|
+
parents: [waitForSleep],
|
|
60
|
+
skipIf: [new parent_condition_1.ParentCondition(waitForSleep, 'output.randomNumber > 50')],
|
|
61
|
+
fn: () => {
|
|
62
|
+
return {
|
|
63
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const rightBranch = exports.taskConditionWorkflow.task({
|
|
68
|
+
name: 'rightBranch',
|
|
69
|
+
parents: [waitForSleep],
|
|
70
|
+
skipIf: [new parent_condition_1.ParentCondition(waitForSleep, 'output.randomNumber <= 50')],
|
|
71
|
+
fn: () => {
|
|
72
|
+
return {
|
|
73
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
// !!
|
|
78
|
+
// > Add wait for event
|
|
79
|
+
const waitForEvent = exports.taskConditionWorkflow.task({
|
|
80
|
+
name: 'waitForEvent',
|
|
81
|
+
parents: [start],
|
|
82
|
+
waitFor: [(0, conditions_1.Or)(new conditions_1.SleepCondition('1m'), new conditions_1.UserEventCondition('wait_for_event:start', 'true'))],
|
|
83
|
+
fn: () => {
|
|
84
|
+
return {
|
|
85
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
// !!
|
|
90
|
+
// > Add sum
|
|
91
|
+
exports.taskConditionWorkflow.task({
|
|
92
|
+
name: 'sum',
|
|
93
|
+
parents: [start, waitForSleep, waitForEvent, skipOnEvent, leftBranch, rightBranch],
|
|
94
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
const one = (yield ctx.parentOutput(start)).randomNumber;
|
|
97
|
+
const two = (yield ctx.parentOutput(waitForEvent)).randomNumber;
|
|
98
|
+
const three = (yield ctx.parentOutput(waitForSleep)).randomNumber;
|
|
99
|
+
const four = ((_a = (yield ctx.parentOutput(skipOnEvent))) === null || _a === void 0 ? void 0 : _a.randomNumber) || 0;
|
|
100
|
+
const five = ((_b = (yield ctx.parentOutput(leftBranch))) === null || _b === void 0 ? void 0 : _b.randomNumber) || 0;
|
|
101
|
+
const six = ((_c = (yield ctx.parentOutput(rightBranch))) === null || _c === void 0 ? void 0 : _c.randomNumber) || 0;
|
|
102
|
+
return {
|
|
103
|
+
sum: one + two + three + four + five + six,
|
|
104
|
+
};
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
// !!
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const event = yield hatchet_client_1.hatchet.events.push('user:event', {
|
|
16
|
+
Data: { Hello: 'World' },
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (require.main === module) {
|
|
21
|
+
main()
|
|
22
|
+
.then(() => process.exit(0))
|
|
23
|
+
.catch((error) => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error('Error:', error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
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
|
+
/* eslint-disable no-console */
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const res = yield workflow_1.dagWithConditions.run({});
|
|
17
|
+
console.log(res['first-task'].Completed);
|
|
18
|
+
console.log(res['second-task'].Completed);
|
|
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,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('dag-worker', {
|
|
17
|
+
workflows: [workflow_1.dagWithConditions],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -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
|
+
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.dagWithConditions = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const conditions_1 = require("../../conditions");
|
|
18
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
exports.dagWithConditions = hatchet_client_1.hatchet.workflow({
|
|
20
|
+
name: 'simple',
|
|
21
|
+
});
|
|
22
|
+
const firstTask = exports.dagWithConditions.task({
|
|
23
|
+
name: 'first-task',
|
|
24
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
yield (0, sleep_1.default)(2000);
|
|
26
|
+
return {
|
|
27
|
+
Completed: true,
|
|
28
|
+
};
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
exports.dagWithConditions.task({
|
|
32
|
+
name: 'second-task',
|
|
33
|
+
parents: [firstTask],
|
|
34
|
+
waitFor: (0, conditions_1.Or)({ eventKey: 'user:event' }, { sleepFor: '10s' }),
|
|
35
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
console.log('triggered by condition', ctx.triggers());
|
|
37
|
+
return {
|
|
38
|
+
Completed: true,
|
|
39
|
+
};
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const EVENT_KEY = "durable-example:event";
|
|
2
|
+
export declare const SLEEP_TIME_SECONDS = 2;
|
|
3
|
+
export declare const SLEEP_TIME: "2s";
|
|
4
|
+
export declare const durableWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
5
|
+
export declare const waitForSleepTwice: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
6
|
+
runtime: number;
|
|
7
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,116 @@
|
|
|
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.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const conditions_1 = require("../../conditions");
|
|
15
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
+
exports.EVENT_KEY = 'durable-example:event';
|
|
17
|
+
exports.SLEEP_TIME_SECONDS = 2;
|
|
18
|
+
exports.SLEEP_TIME = `${exports.SLEEP_TIME_SECONDS}s`;
|
|
19
|
+
// > Create a durable workflow
|
|
20
|
+
exports.durableWorkflow = hatchet_client_1.hatchet.workflow({
|
|
21
|
+
name: 'durable-workflow',
|
|
22
|
+
});
|
|
23
|
+
// !!
|
|
24
|
+
exports.durableWorkflow.task({
|
|
25
|
+
name: 'ephemeral_task',
|
|
26
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
console.log('Running non-durable task');
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
exports.durableWorkflow.durableTask({
|
|
31
|
+
name: 'durable_task',
|
|
32
|
+
executionTimeout: '10m',
|
|
33
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
console.log('Waiting for sleep');
|
|
35
|
+
yield ctx.sleepFor(exports.SLEEP_TIME);
|
|
36
|
+
console.log('Sleep finished');
|
|
37
|
+
console.log('Waiting for event');
|
|
38
|
+
yield ctx.waitFor({ eventKey: exports.EVENT_KEY });
|
|
39
|
+
console.log('Event received');
|
|
40
|
+
return { status: 'success' };
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
function extractKeyAndEventId(waitResult) {
|
|
44
|
+
// DurableContext.waitFor currently returns the CREATE payload directly.
|
|
45
|
+
// The shape is typically `{ [readableDataKey]: { [eventId]: ... } }`.
|
|
46
|
+
const obj = waitResult;
|
|
47
|
+
if (obj && typeof obj === 'object') {
|
|
48
|
+
const key = Object.keys(obj)[0];
|
|
49
|
+
const inner = obj[key];
|
|
50
|
+
if (inner && typeof inner === 'object') {
|
|
51
|
+
const eventId = Object.keys(inner)[0];
|
|
52
|
+
if (eventId) {
|
|
53
|
+
return { key: 'CREATE', eventId };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (key) {
|
|
57
|
+
return { key: 'CREATE', eventId: key };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { key: 'CREATE', eventId: '' };
|
|
61
|
+
}
|
|
62
|
+
exports.durableWorkflow.durableTask({
|
|
63
|
+
name: 'wait_for_or_group_1',
|
|
64
|
+
executionTimeout: '10m',
|
|
65
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const start = Date.now();
|
|
67
|
+
const waitResult = yield ctx.waitFor((0, conditions_1.Or)(new conditions_1.SleepCondition(exports.SLEEP_TIME, 'sleep'), new conditions_1.UserEventCondition(exports.EVENT_KEY, '', 'event')));
|
|
68
|
+
const { key, eventId } = extractKeyAndEventId(waitResult);
|
|
69
|
+
return {
|
|
70
|
+
runtime: Math.round((Date.now() - start) / 1000),
|
|
71
|
+
key,
|
|
72
|
+
eventId,
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
exports.durableWorkflow.durableTask({
|
|
77
|
+
name: 'wait_for_or_group_2',
|
|
78
|
+
executionTimeout: '10m',
|
|
79
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const start = Date.now();
|
|
81
|
+
const waitResult = yield ctx.waitFor((0, conditions_1.Or)(new conditions_1.SleepCondition(`${6 * exports.SLEEP_TIME_SECONDS}s`, 'sleep'), new conditions_1.UserEventCondition(exports.EVENT_KEY, '', 'event')));
|
|
82
|
+
const { key, eventId } = extractKeyAndEventId(waitResult);
|
|
83
|
+
return {
|
|
84
|
+
runtime: Math.round((Date.now() - start) / 1000),
|
|
85
|
+
key,
|
|
86
|
+
eventId,
|
|
87
|
+
};
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
exports.durableWorkflow.durableTask({
|
|
91
|
+
name: 'wait_for_multi_sleep',
|
|
92
|
+
executionTimeout: '10m',
|
|
93
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const start = Date.now();
|
|
95
|
+
// sleep 3 times
|
|
96
|
+
for (let i = 0; i < 3; i += 1) {
|
|
97
|
+
yield ctx.sleepFor(exports.SLEEP_TIME);
|
|
98
|
+
}
|
|
99
|
+
return { runtime: Math.round((Date.now() - start) / 1000) };
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
exports.waitForSleepTwice = hatchet_client_1.hatchet.durableTask({
|
|
103
|
+
name: 'wait-for-sleep-twice',
|
|
104
|
+
executionTimeout: '10m',
|
|
105
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
try {
|
|
107
|
+
const start = Date.now();
|
|
108
|
+
yield ctx.sleepFor(exports.SLEEP_TIME);
|
|
109
|
+
return { runtime: Math.round((Date.now() - start) / 1000) };
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
// treat cancellation as a successful completion for parity with Python sample
|
|
113
|
+
return { runtime: -1 };
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const event = yield hatchet_client_1.hatchet.events.push('user:update', {
|
|
16
|
+
userId: '1234',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (require.main === module) {
|
|
21
|
+
main()
|
|
22
|
+
.then(() => process.exit(0))
|
|
23
|
+
.catch((error) => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error('Error:', error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -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 timeStart = Date.now();
|
|
16
|
+
const res = yield workflow_1.durableEvent.run({});
|
|
17
|
+
const timeEnd = Date.now();
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
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 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('durable-event-worker', {
|
|
17
|
+
workflows: [workflow_1.durableEvent],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const durableEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
2
|
+
Value: string;
|
|
3
|
+
}, {}, {}, {}, {}>;
|
|
4
|
+
export declare const durableEventWithFilter: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
5
|
+
Value: string;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
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.durableEventWithFilter = exports.durableEvent = void 0;
|
|
13
|
+
// import sleep from '../../../util/sleep.js';
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
// > Durable Event
|
|
16
|
+
exports.durableEvent = hatchet_client_1.hatchet.durableTask({
|
|
17
|
+
name: 'durable-event',
|
|
18
|
+
executionTimeout: '10m',
|
|
19
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const res = ctx.waitFor({
|
|
21
|
+
eventKey: 'user:update',
|
|
22
|
+
});
|
|
23
|
+
console.log('res', res);
|
|
24
|
+
return {
|
|
25
|
+
Value: 'done',
|
|
26
|
+
};
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
// !!
|
|
30
|
+
exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
|
|
31
|
+
name: 'durable-event-with-filter',
|
|
32
|
+
executionTimeout: '10m',
|
|
33
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
// > Durable Event With Filter
|
|
35
|
+
const res = ctx.waitFor({
|
|
36
|
+
eventKey: 'user:update',
|
|
37
|
+
expression: "input.userId == '1234'",
|
|
38
|
+
});
|
|
39
|
+
// !!
|
|
40
|
+
console.log('res', res);
|
|
41
|
+
return {
|
|
42
|
+
Value: 'done',
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
// !!
|
|
@@ -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 hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const event = yield hatchet_client_1.hatchet.events.push('user:event', {
|
|
16
|
+
Data: { Hello: 'World' },
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (require.main === module) {
|
|
21
|
+
main()
|
|
22
|
+
.then(() => process.exit(0))
|
|
23
|
+
.catch((error) => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error('Error:', error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -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 timeStart = Date.now();
|
|
16
|
+
const res = yield workflow_1.durableSleep.run({});
|
|
17
|
+
const timeEnd = Date.now();
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
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 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('sleep-worker', {
|
|
17
|
+
workflows: [workflow_1.durableSleep],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const durableSleep: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.durableSleep = void 0;
|
|
13
|
+
// import sleep from '../../../util/sleep.js';
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
exports.durableSleep = hatchet_client_1.hatchet.workflow({
|
|
16
|
+
name: 'durable-sleep',
|
|
17
|
+
});
|
|
18
|
+
// > Durable Sleep
|
|
19
|
+
exports.durableSleep.durableTask({
|
|
20
|
+
name: 'durable-sleep',
|
|
21
|
+
executionTimeout: '10m',
|
|
22
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
console.log('sleeping for 5s');
|
|
24
|
+
const sleepRes = yield ctx.sleepFor('5s');
|
|
25
|
+
console.log('done sleeping for 5s', sleepRes);
|
|
26
|
+
return {
|
|
27
|
+
Value: 'done',
|
|
28
|
+
};
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
// !!
|