@hatchet-dev/typescript-sdk 1.13.0 → 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 +7 -7
- 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,65 @@
|
|
|
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.runDetailTestWorkflow = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
18
|
+
exports.runDetailTestWorkflow = hatchet_client_1.hatchet.workflow({
|
|
19
|
+
name: 'run-detail-test',
|
|
20
|
+
});
|
|
21
|
+
const step1 = exports.runDetailTestWorkflow.task({
|
|
22
|
+
name: 'step1',
|
|
23
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
return ({
|
|
25
|
+
random_number: Math.floor(Math.random() * 100) + 1,
|
|
26
|
+
});
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
const step2 = exports.runDetailTestWorkflow.task({
|
|
30
|
+
name: 'step2',
|
|
31
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
yield (0, sleep_1.default)(5000);
|
|
33
|
+
return {
|
|
34
|
+
random_number: Math.floor(Math.random() * 100) + 1,
|
|
35
|
+
};
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
exports.runDetailTestWorkflow.task({
|
|
39
|
+
name: 'cancel_step',
|
|
40
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
yield ctx.cancel();
|
|
42
|
+
yield (0, sleep_1.default)(10000);
|
|
43
|
+
return {};
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
exports.runDetailTestWorkflow.task({
|
|
47
|
+
name: 'fail_step',
|
|
48
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
throw new Error('Intentional Failure');
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
const step3 = exports.runDetailTestWorkflow.task({
|
|
53
|
+
name: 'step3',
|
|
54
|
+
parents: [step1, step2],
|
|
55
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const one = (yield ctx.parentOutput(step1)).random_number;
|
|
57
|
+
const two = (yield ctx.parentOutput(step2)).random_number;
|
|
58
|
+
return { sum: one + two };
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
exports.runDetailTestWorkflow.task({
|
|
62
|
+
name: 'step4',
|
|
63
|
+
parents: [step1, step3],
|
|
64
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () { return ({ step4: 'step4' }); }),
|
|
65
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const helloWorld: import("../..").TaskWorkflowDeclaration<{
|
|
2
|
+
[x: string]: import("../..").JsonValue;
|
|
3
|
+
} & {
|
|
4
|
+
[x: string]: import("../..").JsonValue;
|
|
5
|
+
}, {
|
|
6
|
+
result: string;
|
|
7
|
+
}, {}, {}, {}, {}>;
|
|
8
|
+
export declare const helloWorldDurable: import("../..").TaskWorkflowDeclaration<{
|
|
9
|
+
[x: string]: import("../..").JsonValue;
|
|
10
|
+
} & {
|
|
11
|
+
[x: string]: import("../..").JsonValue;
|
|
12
|
+
}, {
|
|
13
|
+
result: string;
|
|
14
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.helloWorldDurable = exports.helloWorld = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
// Mirrors `sdks/python/examples/simple/worker.py` outputs for e2e.
|
|
15
|
+
exports.helloWorld = hatchet_client_1.hatchet.task({
|
|
16
|
+
name: 'hello-world',
|
|
17
|
+
fn: (_input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
return { result: 'Hello, world!' };
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
exports.helloWorldDurable = hatchet_client_1.hatchet.durableTask({
|
|
22
|
+
name: 'hello-world-durable',
|
|
23
|
+
executionTimeout: '10m',
|
|
24
|
+
fn: (_input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
return { result: 'Hello, world!' };
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
@@ -29,11 +29,11 @@ function main() {
|
|
|
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
|
-
const result = yield run.
|
|
32
|
+
const result = yield run.output;
|
|
33
33
|
console.log(result);
|
|
34
34
|
// if you need to subscribe to the result of the workflow at a later time, you can use the runRef method and the stored runId
|
|
35
35
|
const ref = hatchet_client_1.hatchet.runRef(runId);
|
|
36
|
-
const result2 = yield ref.
|
|
36
|
+
const result2 = yield ref.output;
|
|
37
37
|
console.log(result2);
|
|
38
38
|
// !!
|
|
39
39
|
});
|
|
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sticky = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
|
-
const
|
|
14
|
+
const v1_1 = require("../..");
|
|
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,
|
|
21
|
-
sticky:
|
|
21
|
+
sticky: v1_1.StickyStrategy.SOFT,
|
|
22
22
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
// specify a child workflow to run on the same worker
|
|
24
24
|
const result = yield workflow_1.child.run({
|
|
@@ -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
|
+
/* 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
|
+
yield workflow_1.timeoutTask.run({ Message: 'hello' });
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.log('timeoutTask failed as expected', e);
|
|
21
|
+
}
|
|
22
|
+
const res = yield workflow_1.refreshTimeoutTask.run({ Message: 'hello' });
|
|
23
|
+
console.log(res);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
main()
|
|
28
|
+
.catch(console.error)
|
|
29
|
+
.finally(() => process.exit(0));
|
|
30
|
+
}
|
|
@@ -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 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('timeout-worker', {
|
|
17
|
+
workflows: [workflow_1.timeoutTask, workflow_1.refreshTimeoutTask],
|
|
18
|
+
slots: 50,
|
|
19
|
+
});
|
|
20
|
+
yield worker.start();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (require.main === module) {
|
|
24
|
+
main();
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SimpleInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const timeoutTask: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
5
|
+
status: string;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
7
|
+
export declare const refreshTimeoutTask: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
8
|
+
status: string;
|
|
9
|
+
message: string;
|
|
10
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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.refreshTimeoutTask = exports.timeoutTask = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
18
|
+
// > Execution Timeout
|
|
19
|
+
// Mirrors Python `examples/timeout/test_timeout.py::test_execution_timeout`
|
|
20
|
+
exports.timeoutTask = hatchet_client_1.hatchet.task({
|
|
21
|
+
name: 'timeout',
|
|
22
|
+
executionTimeout: '3s',
|
|
23
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
yield (0, sleep_1.default)(10 * 1000, ctx.abortController.signal);
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
throw new Error('Task was cancelled');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
status: 'success',
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
// !!
|
|
36
|
+
// > Refresh Timeout
|
|
37
|
+
// Mirrors Python `examples/timeout/test_timeout.py::test_run_refresh_timeout`
|
|
38
|
+
exports.refreshTimeoutTask = hatchet_client_1.hatchet.task({
|
|
39
|
+
name: 'refresh-timeout',
|
|
40
|
+
executionTimeout: '3s',
|
|
41
|
+
scheduleTimeout: '5s',
|
|
42
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
ctx.refreshTimeout('5s');
|
|
44
|
+
try {
|
|
45
|
+
yield (0, sleep_1.default)(4000, ctx.abortController.signal);
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
throw new Error('cancelled');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
status: 'success',
|
|
52
|
+
message: input.Message.toLowerCase(),
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
// !!
|
|
@@ -0,0 +1,23 @@
|
|
|
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.webhookWorkflow = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
exports.webhookWorkflow = hatchet_client_1.hatchet.workflow({
|
|
15
|
+
name: 'webhook-workflow',
|
|
16
|
+
onEvents: ['webhook:test'],
|
|
17
|
+
});
|
|
18
|
+
exports.webhookWorkflow.task({
|
|
19
|
+
name: 'webhook-task',
|
|
20
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return input;
|
|
22
|
+
}),
|
|
23
|
+
});
|
package/v1/index.d.ts
CHANGED
package/v1/index.js
CHANGED
|
@@ -6,10 +6,16 @@ export interface ParentRunContext {
|
|
|
6
6
|
parentTaskRunExternalId: string;
|
|
7
7
|
desiredWorkerId: string;
|
|
8
8
|
childIndex?: number;
|
|
9
|
+
/**
|
|
10
|
+
* (optional) AbortSignal inherited by nested `run()` calls.
|
|
11
|
+
* Used to cancel local "wait for result" subscriptions when the parent task is cancelled.
|
|
12
|
+
*/
|
|
13
|
+
signal?: AbortSignal;
|
|
9
14
|
}
|
|
10
15
|
export declare class ParentRunContextManager {
|
|
11
16
|
private storage;
|
|
12
17
|
constructor();
|
|
18
|
+
runWithContext<T>(opts: ParentRunContext, fn: () => T): T;
|
|
13
19
|
setContext(opts: ParentRunContext): void;
|
|
14
20
|
setParentRunIdAndIncrementChildIndex(opts: ParentRunContext): void;
|
|
15
21
|
incrementChildIndex(n: number): void;
|
|
@@ -6,6 +6,9 @@ class ParentRunContextManager {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
this.storage = new async_hooks_1.AsyncLocalStorage();
|
|
8
8
|
}
|
|
9
|
+
runWithContext(opts, fn) {
|
|
10
|
+
return this.storage.run(Object.assign({}, opts), fn);
|
|
11
|
+
}
|
|
9
12
|
setContext(opts) {
|
|
10
13
|
this.storage.enterWith(Object.assign({}, opts));
|
|
11
14
|
}
|
package/v1/task.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ConcurrencyLimitStrategy } from '../protoc/v1/workflows';
|
|
2
|
-
import { CreateStep } from '../step';
|
|
1
|
+
import { ConcurrencyLimitStrategy, RateLimitDuration, WorkerLabelComparator } from '../protoc/v1/workflows';
|
|
3
2
|
import { Conditions } from './conditions';
|
|
4
3
|
import { Duration } from './client/duration';
|
|
5
4
|
import { InputType, OutputType, UnknownInputType } from './types';
|
|
6
5
|
import { Context, DurableContext } from './client/worker/context';
|
|
6
|
+
export { ConcurrencyLimitStrategy, WorkerLabelComparator };
|
|
7
7
|
/**
|
|
8
8
|
* Options for configuring the concurrency for a task.
|
|
9
9
|
*/
|
|
@@ -59,7 +59,7 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
59
59
|
/**
|
|
60
60
|
* @deprecated use executionTimeout instead
|
|
61
61
|
*/
|
|
62
|
-
timeout?:
|
|
62
|
+
timeout?: Duration;
|
|
63
63
|
/**
|
|
64
64
|
* (optional) execution timeout duration for the task after it starts running
|
|
65
65
|
* go duration format (e.g., "1s", "5m", "1h").
|
|
@@ -79,17 +79,27 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
79
79
|
*
|
|
80
80
|
* default: 0
|
|
81
81
|
*/
|
|
82
|
-
retries?:
|
|
82
|
+
retries?: number;
|
|
83
83
|
/**
|
|
84
84
|
* (optional) backoff strategy configuration for retries.
|
|
85
85
|
* - factor: Base of the exponential backoff (base ^ retry count)
|
|
86
86
|
* - maxSeconds: Maximum backoff duration in seconds
|
|
87
87
|
*/
|
|
88
|
-
backoff?:
|
|
88
|
+
backoff?: {
|
|
89
|
+
factor?: number | undefined;
|
|
90
|
+
maxSeconds?: number | undefined;
|
|
91
|
+
};
|
|
89
92
|
/**
|
|
90
93
|
* (optional) rate limits for the task.
|
|
91
94
|
*/
|
|
92
|
-
rateLimits?:
|
|
95
|
+
rateLimits?: {
|
|
96
|
+
units: string | number;
|
|
97
|
+
key?: string;
|
|
98
|
+
staticKey?: string;
|
|
99
|
+
dynamicKey?: string;
|
|
100
|
+
limit?: string | number;
|
|
101
|
+
duration?: RateLimitDuration;
|
|
102
|
+
}[];
|
|
93
103
|
/**
|
|
94
104
|
* (optional) worker labels for task routing and scheduling.
|
|
95
105
|
* Each label can be a simple string/number value or an object with additional configuration:
|
|
@@ -98,7 +108,12 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
98
108
|
* - weight: Priority weight for worker selection
|
|
99
109
|
* - comparator: Custom comparison logic for label matching
|
|
100
110
|
*/
|
|
101
|
-
desiredWorkerLabels?:
|
|
111
|
+
desiredWorkerLabels?: Record<string, {
|
|
112
|
+
value: string | number;
|
|
113
|
+
required?: boolean;
|
|
114
|
+
weight?: number;
|
|
115
|
+
comparator?: WorkerLabelComparator;
|
|
116
|
+
}>;
|
|
102
117
|
/**
|
|
103
118
|
* (optional) the concurrency options for the task
|
|
104
119
|
*/
|
package/v1/task.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonRetryableError = void 0;
|
|
3
|
+
exports.NonRetryableError = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = void 0;
|
|
4
|
+
const workflows_1 = require("../protoc/v1/workflows");
|
|
5
|
+
Object.defineProperty(exports, "ConcurrencyLimitStrategy", { enumerable: true, get: function () { return workflows_1.ConcurrencyLimitStrategy; } });
|
|
6
|
+
Object.defineProperty(exports, "WorkerLabelComparator", { enumerable: true, get: function () { return workflows_1.WorkerLabelComparator; } });
|
|
4
7
|
class NonRetryableError extends Error {
|
|
5
8
|
constructor(message) {
|
|
6
9
|
super(message);
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.14.0";
|
package/version.js
CHANGED