@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,69 @@
|
|
|
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.abortSignal = exports.cancellationWorkflow = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
// > Self-cancelling workflow (mirrors Python example)
|
|
20
|
+
exports.cancellationWorkflow = hatchet_client_1.hatchet.workflow({
|
|
21
|
+
name: 'CancelWorkflow',
|
|
22
|
+
});
|
|
23
|
+
exports.cancellationWorkflow.task({
|
|
24
|
+
name: 'self-cancel',
|
|
25
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
yield (0, sleep_1.default)(2000, ctx.abortController.signal);
|
|
27
|
+
// Cancel the current task run (server-side) and optimistically abort local execution.
|
|
28
|
+
yield ctx.cancel();
|
|
29
|
+
// If cancellation didn't stop execution yet, keep waiting but cooperatively.
|
|
30
|
+
yield (0, sleep_1.default)(10000, ctx.abortController.signal);
|
|
31
|
+
return { error: 'Task should have been cancelled' };
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
exports.cancellationWorkflow.task({
|
|
35
|
+
name: 'check-flag',
|
|
36
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
for (let i = 0; i < 3; i += 1) {
|
|
38
|
+
yield (0, sleep_1.default)(1000, ctx.abortController.signal);
|
|
39
|
+
if (ctx.cancelled) {
|
|
40
|
+
throw new Error('Cancelled');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { error: 'Task should have been cancelled' };
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
// !!
|
|
47
|
+
// > Abort Signal
|
|
48
|
+
exports.abortSignal = hatchet_client_1.hatchet.task({
|
|
49
|
+
name: 'abort-signal',
|
|
50
|
+
fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { abortController }) {
|
|
51
|
+
try {
|
|
52
|
+
const response = yield axios_1.default.get('https://api.example.com/data', {
|
|
53
|
+
signal: abortController.signal,
|
|
54
|
+
});
|
|
55
|
+
// Handle the response
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (axios_1.default.isCancel(error)) {
|
|
59
|
+
// Request was canceled
|
|
60
|
+
console.log('Request canceled');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Handle other errors
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
// !!
|
|
69
|
+
// see ./worker.ts and ./run.ts for how to run the workflow
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
/* eslint-disable no-console */
|
|
16
|
+
// > Running a Task with Results
|
|
17
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
|
+
const cancellation_workflow_1 = require("./cancellation-workflow");
|
|
19
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
20
|
+
// ...
|
|
21
|
+
function main() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const run = yield cancellation_workflow_1.cancellationWorkflow.runNoWait({});
|
|
24
|
+
const run1 = yield cancellation_workflow_1.cancellationWorkflow.runNoWait({});
|
|
25
|
+
yield (0, sleep_1.default)(1000);
|
|
26
|
+
yield run.cancel();
|
|
27
|
+
const res = yield run.output;
|
|
28
|
+
const res1 = yield run1.output;
|
|
29
|
+
console.log('canceled', res);
|
|
30
|
+
console.log('completed', res1);
|
|
31
|
+
yield (0, sleep_1.default)(1000);
|
|
32
|
+
yield run.replay();
|
|
33
|
+
const resReplay = yield run.output;
|
|
34
|
+
console.log(resReplay);
|
|
35
|
+
const run2 = yield cancellation_workflow_1.cancellationWorkflow.runNoWait({}, { additionalMetadata: { test: 'abc' } });
|
|
36
|
+
const run4 = yield cancellation_workflow_1.cancellationWorkflow.runNoWait({}, { additionalMetadata: { test: 'test' } });
|
|
37
|
+
yield (0, sleep_1.default)(1000);
|
|
38
|
+
yield hatchet_client_1.hatchet.runs.cancel({
|
|
39
|
+
filters: {
|
|
40
|
+
since: new Date(Date.now() - 60 * 60),
|
|
41
|
+
additionalMetadata: { test: 'test' },
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const res3 = yield Promise.all([run2.output, run4.output]);
|
|
45
|
+
console.log(res3);
|
|
46
|
+
// !!
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (require.main === module) {
|
|
50
|
+
main()
|
|
51
|
+
.catch(console.error)
|
|
52
|
+
.finally(() => process.exit(0));
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
// > Declaring a Worker
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
const cancellation_workflow_1 = require("./cancellation-workflow");
|
|
15
|
+
function main() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const worker = yield hatchet_client_1.hatchet.worker('cancellation-worker', {
|
|
18
|
+
// 👀 Declare the workflows that the worker can execute
|
|
19
|
+
workflows: [cancellation_workflow_1.cancellationWorkflow],
|
|
20
|
+
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
21
|
+
slots: 100,
|
|
22
|
+
});
|
|
23
|
+
yield worker.start();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
main();
|
|
28
|
+
}
|
|
29
|
+
// !!
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EmptyTaskOutput } from '../concurrency-types';
|
|
2
|
+
export type WorkflowInput = {
|
|
3
|
+
group: string;
|
|
4
|
+
};
|
|
5
|
+
export type WorkflowOutput = {
|
|
6
|
+
step1: EmptyTaskOutput;
|
|
7
|
+
step2: EmptyTaskOutput;
|
|
8
|
+
};
|
|
9
|
+
export declare const concurrencyCancelInProgressWorkflow: import("../..").WorkflowDeclaration<WorkflowInput, WorkflowOutput, {}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
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.concurrencyCancelInProgressWorkflow = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const v1_1 = require("../..");
|
|
18
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
exports.concurrencyCancelInProgressWorkflow = hatchet_client_1.hatchet.workflow({
|
|
20
|
+
name: 'concurrencycancelinprogress',
|
|
21
|
+
concurrency: {
|
|
22
|
+
expression: 'input.group',
|
|
23
|
+
maxRuns: 1,
|
|
24
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const step1 = exports.concurrencyCancelInProgressWorkflow.task({
|
|
28
|
+
name: 'step1',
|
|
29
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
for (let i = 0; i < 50; i += 1) {
|
|
31
|
+
yield (0, sleep_1.default)(100, ctx.abortController.signal);
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
exports.concurrencyCancelInProgressWorkflow.task({
|
|
37
|
+
name: 'step2',
|
|
38
|
+
parents: [step1],
|
|
39
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
for (let i = 0; i < 50; i += 1) {
|
|
41
|
+
yield (0, sleep_1.default)(100, ctx.abortController.signal);
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EmptyTaskOutput } from '../concurrency-types';
|
|
2
|
+
export type WorkflowInput = {
|
|
3
|
+
group: string;
|
|
4
|
+
};
|
|
5
|
+
export type WorkflowOutput = {
|
|
6
|
+
step1: EmptyTaskOutput;
|
|
7
|
+
step2: EmptyTaskOutput;
|
|
8
|
+
};
|
|
9
|
+
export declare const concurrencyCancelNewestWorkflow: import("../..").WorkflowDeclaration<WorkflowInput, WorkflowOutput, {}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
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.concurrencyCancelNewestWorkflow = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const v1_1 = require("../..");
|
|
18
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
exports.concurrencyCancelNewestWorkflow = hatchet_client_1.hatchet.workflow({
|
|
20
|
+
name: 'concurrencycancelnewest',
|
|
21
|
+
concurrency: {
|
|
22
|
+
expression: 'input.group',
|
|
23
|
+
maxRuns: 1,
|
|
24
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.CANCEL_NEWEST,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const step1 = exports.concurrencyCancelNewestWorkflow.task({
|
|
28
|
+
name: 'step1',
|
|
29
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
for (let i = 0; i < 50; i += 1) {
|
|
31
|
+
yield (0, sleep_1.default)(20, ctx.abortController.signal);
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
exports.concurrencyCancelNewestWorkflow.task({
|
|
37
|
+
name: 'step2',
|
|
38
|
+
parents: [step1],
|
|
39
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
for (let i = 0; i < 50; i += 1) {
|
|
41
|
+
yield (0, sleep_1.default)(20, ctx.abortController.signal);
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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-plusplus */
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
function generateRandomString(length) {
|
|
16
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
17
|
+
let result = '';
|
|
18
|
+
for (let i = 0; i < length; i++) {
|
|
19
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function main() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const groupCount = 2;
|
|
26
|
+
const runsPerGroup = 20000;
|
|
27
|
+
const BATCH_SIZE = 400;
|
|
28
|
+
const workflowRuns = [];
|
|
29
|
+
for (let i = 0; i < groupCount; i++) {
|
|
30
|
+
for (let j = 0; j < runsPerGroup; j++) {
|
|
31
|
+
workflowRuns.push({
|
|
32
|
+
workflowName: workflow_1.simpleConcurrency.definition.name,
|
|
33
|
+
input: {
|
|
34
|
+
Message: generateRandomString(10),
|
|
35
|
+
GroupKey: `group-${i}`,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Shuffle the workflow runs array
|
|
41
|
+
for (let i = workflowRuns.length - 1; i > 0; i--) {
|
|
42
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
43
|
+
[workflowRuns[i], workflowRuns[j]] = [workflowRuns[j], workflowRuns[i]];
|
|
44
|
+
}
|
|
45
|
+
// Process workflows in batches
|
|
46
|
+
for (let i = 0; i < workflowRuns.length; i += BATCH_SIZE) {
|
|
47
|
+
const batch = workflowRuns.slice(i, i + BATCH_SIZE);
|
|
48
|
+
yield hatchet_client_1.hatchet.admin.runWorkflows(batch);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (require.main === module) {
|
|
53
|
+
main().then(() => process.exit(0));
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.simpleConcurrency.run([
|
|
16
|
+
{
|
|
17
|
+
Message: 'Hello World',
|
|
18
|
+
GroupKey: 'A',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
Message: 'Goodbye Moon',
|
|
22
|
+
GroupKey: 'A',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
Message: 'Hello World B',
|
|
26
|
+
GroupKey: 'B',
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(res[0]['to-lower'].TransformedMessage);
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(res[1]['to-lower'].TransformedMessage);
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.log(res[2]['to-lower'].TransformedMessage);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (require.main === module) {
|
|
38
|
+
main().then(() => process.exit(0));
|
|
39
|
+
}
|
|
@@ -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('simple-concurrency-worker', {
|
|
17
|
+
workflows: [workflow_1.simpleConcurrency],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type SimpleInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
GroupKey: string;
|
|
4
|
+
};
|
|
5
|
+
type SimpleOutput = {
|
|
6
|
+
'to-lower': {
|
|
7
|
+
TransformedMessage: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const simpleConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput, {}>;
|
|
11
|
+
export declare const multipleConcurrencyKeys: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput, {}>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
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.multipleConcurrencyKeys = exports.simpleConcurrency = void 0;
|
|
13
|
+
const v1_1 = require("../..");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
16
|
+
setTimeout(resolve, ms);
|
|
17
|
+
});
|
|
18
|
+
// > Concurrency Strategy With Key
|
|
19
|
+
exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
|
|
20
|
+
name: 'simple-concurrency',
|
|
21
|
+
concurrency: {
|
|
22
|
+
maxRuns: 1,
|
|
23
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
24
|
+
expression: 'input.GroupKey',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
// !!
|
|
28
|
+
exports.simpleConcurrency.task({
|
|
29
|
+
name: 'to-lower',
|
|
30
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
yield sleep(Math.floor(Math.random() * (1000 - 200 + 1)) + 200);
|
|
32
|
+
return {
|
|
33
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
// > Multiple Concurrency Keys
|
|
38
|
+
exports.multipleConcurrencyKeys = hatchet_client_1.hatchet.workflow({
|
|
39
|
+
name: 'simple-concurrency',
|
|
40
|
+
concurrency: [
|
|
41
|
+
{
|
|
42
|
+
maxRuns: 1,
|
|
43
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
44
|
+
expression: 'input.Tier',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
maxRuns: 1,
|
|
48
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
49
|
+
expression: 'input.Account',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
// !!
|
|
54
|
+
exports.multipleConcurrencyKeys.task({
|
|
55
|
+
name: 'to-lower',
|
|
56
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
yield sleep(Math.floor(Math.random() * (1000 - 200 + 1)) + 200);
|
|
58
|
+
return {
|
|
59
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EmptyTaskOutput } from '../concurrency-types';
|
|
2
|
+
export declare const SLEEP_TIME_MS = 500;
|
|
3
|
+
export declare const DIGIT_MAX_RUNS = 8;
|
|
4
|
+
export declare const NAME_MAX_RUNS = 3;
|
|
5
|
+
export type WorkflowInput = {
|
|
6
|
+
name: string;
|
|
7
|
+
digit: string;
|
|
8
|
+
};
|
|
9
|
+
export type WorkflowOutput = {
|
|
10
|
+
concurrency_task: EmptyTaskOutput;
|
|
11
|
+
};
|
|
12
|
+
export declare const concurrencyMultipleKeysWorkflow: import("../..").WorkflowDeclaration<WorkflowInput, WorkflowOutput, {}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
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.concurrencyMultipleKeysWorkflow = exports.NAME_MAX_RUNS = exports.DIGIT_MAX_RUNS = exports.SLEEP_TIME_MS = void 0;
|
|
13
|
+
const v1_1 = require("../..");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
16
|
+
setTimeout(resolve, ms);
|
|
17
|
+
});
|
|
18
|
+
exports.SLEEP_TIME_MS = 500;
|
|
19
|
+
exports.DIGIT_MAX_RUNS = 8;
|
|
20
|
+
exports.NAME_MAX_RUNS = 3;
|
|
21
|
+
exports.concurrencyMultipleKeysWorkflow = hatchet_client_1.hatchet.workflow({
|
|
22
|
+
name: 'concurrency-workflow-many-keys',
|
|
23
|
+
concurrency: [
|
|
24
|
+
{
|
|
25
|
+
expression: 'input.digit',
|
|
26
|
+
maxRuns: exports.DIGIT_MAX_RUNS,
|
|
27
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
expression: 'input.name',
|
|
31
|
+
maxRuns: exports.NAME_MAX_RUNS,
|
|
32
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
exports.concurrencyMultipleKeysWorkflow.task({
|
|
37
|
+
name: 'concurrency_task',
|
|
38
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
yield sleep(exports.SLEEP_TIME_MS);
|
|
40
|
+
return {};
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EmptyTaskOutput } from '../concurrency-types';
|
|
2
|
+
export declare const SLEEP_TIME_MS = 500;
|
|
3
|
+
export declare const DIGIT_MAX_RUNS = 8;
|
|
4
|
+
export declare const NAME_MAX_RUNS = 3;
|
|
5
|
+
export type WorkflowInput = {
|
|
6
|
+
name: string;
|
|
7
|
+
digit: string;
|
|
8
|
+
};
|
|
9
|
+
export type WorkflowOutput = {
|
|
10
|
+
task_1: EmptyTaskOutput;
|
|
11
|
+
task_2: EmptyTaskOutput;
|
|
12
|
+
};
|
|
13
|
+
export declare const concurrencyWorkflowLevelWorkflow: import("../..").WorkflowDeclaration<WorkflowInput, WorkflowOutput, {}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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.concurrencyWorkflowLevelWorkflow = exports.NAME_MAX_RUNS = exports.DIGIT_MAX_RUNS = exports.SLEEP_TIME_MS = void 0;
|
|
13
|
+
const v1_1 = require("../..");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
16
|
+
setTimeout(resolve, ms);
|
|
17
|
+
});
|
|
18
|
+
exports.SLEEP_TIME_MS = 500;
|
|
19
|
+
exports.DIGIT_MAX_RUNS = 8;
|
|
20
|
+
exports.NAME_MAX_RUNS = 3;
|
|
21
|
+
exports.concurrencyWorkflowLevelWorkflow = hatchet_client_1.hatchet.workflow({
|
|
22
|
+
name: 'concurrency-workflow-level',
|
|
23
|
+
concurrency: [
|
|
24
|
+
{
|
|
25
|
+
expression: 'input.digit',
|
|
26
|
+
maxRuns: exports.DIGIT_MAX_RUNS,
|
|
27
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
expression: 'input.name',
|
|
31
|
+
maxRuns: exports.NAME_MAX_RUNS,
|
|
32
|
+
limitStrategy: v1_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
exports.concurrencyWorkflowLevelWorkflow.task({
|
|
37
|
+
name: 'task_1',
|
|
38
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
yield sleep(exports.SLEEP_TIME_MS);
|
|
40
|
+
return {};
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
exports.concurrencyWorkflowLevelWorkflow.task({
|
|
44
|
+
name: 'task_2',
|
|
45
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
yield sleep(exports.SLEEP_TIME_MS);
|
|
47
|
+
return {};
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const taskConditionWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|