@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
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
|
|
2
|
-
import { LegacyHatchetClient } from '../../../clients/hatchet-client';
|
|
3
|
-
import { Workflow as V0Workflow } from '../../../workflow';
|
|
4
|
-
import { WebhookWorkerCreateRequest } from '../../../clients/rest/generated/data-contracts';
|
|
5
2
|
import { BaseWorkflowDeclaration } from '../../declaration';
|
|
3
|
+
import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
|
|
6
4
|
import { HatchetClient } from '../..';
|
|
7
|
-
import {
|
|
5
|
+
import { InternalWorker } from './worker-internal';
|
|
8
6
|
import { type WorkerSlotOptions } from './slot-utils';
|
|
9
7
|
/**
|
|
10
8
|
* Options for creating a new hatchet worker
|
|
@@ -23,9 +21,8 @@ export declare class Worker {
|
|
|
23
21
|
config: CreateWorkerOpts;
|
|
24
22
|
name: string;
|
|
25
23
|
_v1: HatchetClient;
|
|
26
|
-
_v0: LegacyHatchetClient;
|
|
27
24
|
/** Internal reference to the underlying V0 worker implementation */
|
|
28
|
-
_internal:
|
|
25
|
+
_internal: InternalWorker;
|
|
29
26
|
/** Set when connected to a legacy engine that needs dual-worker architecture */
|
|
30
27
|
private _legacyWorker;
|
|
31
28
|
/** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
|
|
@@ -34,27 +31,31 @@ export declare class Worker {
|
|
|
34
31
|
* Creates a new HatchetWorker instance
|
|
35
32
|
* @param nonDurable - The V0 worker implementation
|
|
36
33
|
*/
|
|
37
|
-
constructor(v1: HatchetClient,
|
|
34
|
+
constructor(v1: HatchetClient, nonDurable: InternalWorker, config: CreateWorkerOpts, name: string);
|
|
38
35
|
/**
|
|
39
36
|
* Creates and initializes a new HatchetWorker
|
|
40
37
|
* @param v0 - The HatchetClient instance
|
|
41
38
|
* @param options - Worker creation options
|
|
42
39
|
* @returns A new HatchetWorker instance
|
|
43
40
|
*/
|
|
44
|
-
static create(v1: HatchetClient,
|
|
41
|
+
static create(v1: HatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
|
|
45
42
|
/**
|
|
46
|
-
* Registers workflows with the worker
|
|
43
|
+
* Registers workflows with the worker.
|
|
44
|
+
* Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
|
|
45
|
+
* Legacy workflows are automatically transformed and a deprecation warning is emitted.
|
|
47
46
|
* @param workflows - Array of workflows to register
|
|
48
47
|
* @returns Array of registered workflow promises
|
|
49
48
|
*/
|
|
50
|
-
registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> |
|
|
49
|
+
registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | LegacyWorkflow>): Promise<void>;
|
|
51
50
|
/**
|
|
52
|
-
* Registers a single workflow with the worker
|
|
51
|
+
* Registers a single workflow with the worker.
|
|
52
|
+
* Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
|
|
53
|
+
* Legacy workflows are automatically transformed and a deprecation warning is emitted.
|
|
53
54
|
* @param workflow - The workflow to register
|
|
54
55
|
* @returns A promise that resolves when the workflow is registered
|
|
55
56
|
* @deprecated use registerWorkflows instead
|
|
56
57
|
*/
|
|
57
|
-
registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> |
|
|
58
|
+
registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<void>;
|
|
58
59
|
/**
|
|
59
60
|
* Starts the worker
|
|
60
61
|
* @returns Promise that resolves when the worker is stopped or killed
|
|
@@ -76,14 +77,13 @@ export declare class Worker {
|
|
|
76
77
|
* @returns The labels for the worker
|
|
77
78
|
*/
|
|
78
79
|
getLabels(): WorkerLabels;
|
|
79
|
-
/**
|
|
80
|
-
* Register a webhook with the worker
|
|
81
|
-
* @param webhook - The webhook to register
|
|
82
|
-
* @returns A promise that resolves when the webhook is registered
|
|
83
|
-
*/
|
|
84
|
-
registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
|
|
85
80
|
isPaused(): Promise<boolean>;
|
|
86
81
|
pause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
|
|
87
82
|
unpause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
|
|
83
|
+
/**
|
|
84
|
+
* Waits until the worker has connected and registered with the server.
|
|
85
|
+
* Polls every 200ms. Use after start() to avoid fixed sleeps before running workflows.
|
|
86
|
+
*/
|
|
87
|
+
waitUntilReady(timeoutMs?: number): Promise<void>;
|
|
88
88
|
}
|
|
89
89
|
export { testingExports as __testing } from './slot-utils';
|
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.__testing = exports.Worker = void 0;
|
|
13
|
-
const
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const legacy_transformer_1 = require("../../../legacy/legacy-transformer");
|
|
14
18
|
const worker_internal_1 = require("./worker-internal");
|
|
15
19
|
const slot_utils_1 = require("./slot-utils");
|
|
16
20
|
const deprecated_1 = require("./deprecated");
|
|
@@ -22,11 +26,10 @@ class Worker {
|
|
|
22
26
|
* Creates a new HatchetWorker instance
|
|
23
27
|
* @param nonDurable - The V0 worker implementation
|
|
24
28
|
*/
|
|
25
|
-
constructor(v1,
|
|
29
|
+
constructor(v1, nonDurable, config, name) {
|
|
26
30
|
/** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
|
|
27
31
|
this._registeredWorkflows = [];
|
|
28
32
|
this._v1 = v1;
|
|
29
|
-
this._v0 = v0;
|
|
30
33
|
this._internal = nonDurable;
|
|
31
34
|
this.config = config;
|
|
32
35
|
this.name = name;
|
|
@@ -37,41 +40,40 @@ class Worker {
|
|
|
37
40
|
* @param options - Worker creation options
|
|
38
41
|
* @returns A new HatchetWorker instance
|
|
39
42
|
*/
|
|
40
|
-
static create(v1,
|
|
43
|
+
static create(v1, name, options) {
|
|
41
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
45
|
+
// Normalize any legacy workflows before resolving worker options
|
|
46
|
+
const normalizedOptions = Object.assign(Object.assign({}, options), { workflows: options.workflows ? (0, legacy_transformer_1.normalizeWorkflows)(options.workflows) : undefined });
|
|
47
|
+
const resolvedOptions = (0, slot_utils_1.resolveWorkerOptions)(normalizedOptions);
|
|
43
48
|
const opts = Object.assign({ name }, resolvedOptions);
|
|
44
|
-
const internalWorker = new worker_internal_1.
|
|
45
|
-
const worker = new Worker(v1,
|
|
46
|
-
yield worker.registerWorkflows(
|
|
49
|
+
const internalWorker = new worker_internal_1.InternalWorker(v1, opts);
|
|
50
|
+
const worker = new Worker(v1, internalWorker, normalizedOptions, name);
|
|
51
|
+
yield worker.registerWorkflows(normalizedOptions.workflows);
|
|
47
52
|
return worker;
|
|
48
53
|
});
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
|
-
* Registers workflows with the worker
|
|
56
|
+
* Registers workflows with the worker.
|
|
57
|
+
* Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
|
|
58
|
+
* Legacy workflows are automatically transformed and a deprecation warning is emitted.
|
|
52
59
|
* @param workflows - Array of workflows to register
|
|
53
60
|
* @returns Array of registered workflow promises
|
|
54
61
|
*/
|
|
55
62
|
registerWorkflows(workflows) {
|
|
56
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (wf.definition._durableTasks.length > 0) {
|
|
63
|
-
this._internal.registerDurableActionsV1(wf.definition);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// fallback to v0 client for backwards compatibility
|
|
68
|
-
yield this._internal.registerWorkflow(wf);
|
|
64
|
+
const normalized = workflows ? (0, legacy_transformer_1.normalizeWorkflows)(workflows) : [];
|
|
65
|
+
for (const wf of normalized) {
|
|
66
|
+
yield this._internal.registerWorkflow(wf);
|
|
67
|
+
if (wf.definition._durableTasks.length > 0) {
|
|
68
|
+
this._internal.registerDurableActions(wf.definition);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Registers a single workflow with the worker
|
|
74
|
+
* Registers a single workflow with the worker.
|
|
75
|
+
* Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
|
|
76
|
+
* Legacy workflows are automatically transformed and a deprecation warning is emitted.
|
|
75
77
|
* @param workflow - The workflow to register
|
|
76
78
|
* @returns A promise that resolves when the workflow is registered
|
|
77
79
|
* @deprecated use registerWorkflows instead
|
|
@@ -123,14 +125,6 @@ class Worker {
|
|
|
123
125
|
getLabels() {
|
|
124
126
|
return this._internal.labels;
|
|
125
127
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Register a webhook with the worker
|
|
128
|
-
* @param webhook - The webhook to register
|
|
129
|
-
* @returns A promise that resolves when the webhook is registered
|
|
130
|
-
*/
|
|
131
|
-
registerWebhook(webhook) {
|
|
132
|
-
return this._internal.registerWebhook(webhook);
|
|
133
|
-
}
|
|
134
128
|
isPaused() {
|
|
135
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
130
|
var _a;
|
|
@@ -155,6 +149,27 @@ class Worker {
|
|
|
155
149
|
}
|
|
156
150
|
return this._v1.workers.unpause(this._internal.workerId);
|
|
157
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Waits until the worker has connected and registered with the server.
|
|
154
|
+
* Polls every 200ms. Use after start() to avoid fixed sleeps before running workflows.
|
|
155
|
+
*/
|
|
156
|
+
waitUntilReady() {
|
|
157
|
+
return __awaiter(this, arguments, void 0, function* (timeoutMs = 10000) {
|
|
158
|
+
var _a;
|
|
159
|
+
if (this._legacyWorker) {
|
|
160
|
+
yield (0, sleep_1.default)(2000);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pollInterval = 200;
|
|
164
|
+
const start = Date.now();
|
|
165
|
+
while (Date.now() - start < timeoutMs) {
|
|
166
|
+
if ((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)
|
|
167
|
+
return;
|
|
168
|
+
yield (0, sleep_1.default)(pollInterval);
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`Worker ${this.name} did not become ready within ${timeoutMs}ms`);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
158
173
|
}
|
|
159
174
|
exports.Worker = Worker;
|
|
160
175
|
var slot_utils_2 = require("./slot-utils");
|
package/v1/declaration.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import WorkflowRunRef from '../util/workflow-run-ref';
|
|
2
2
|
import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
|
|
3
|
-
import { Workflow as WorkflowV0 } from '../workflow';
|
|
4
3
|
import { z } from 'zod';
|
|
5
4
|
import { IHatchetClient } from './client/client.interface';
|
|
6
5
|
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
|
|
@@ -41,6 +40,12 @@ export type RunOpts = {
|
|
|
41
40
|
* only used if spawned from within a parent task.
|
|
42
41
|
*/
|
|
43
42
|
childKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* (optional) when running multiple workflows (array input), if true, return
|
|
45
|
+
* exceptions in the result array instead of throwing. Successes are outputs,
|
|
46
|
+
* failures are Error instances.
|
|
47
|
+
*/
|
|
48
|
+
returnExceptions?: boolean;
|
|
44
49
|
};
|
|
45
50
|
/**
|
|
46
51
|
* Helper type to safely extract output types from task results
|
|
@@ -51,28 +56,44 @@ export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key,
|
|
|
51
56
|
*/
|
|
52
57
|
export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
|
|
53
58
|
type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
|
|
59
|
+
/**
|
|
60
|
+
* Sticky strategy for workflow scheduling.
|
|
61
|
+
*
|
|
62
|
+
* Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
|
|
63
|
+
* For backwards compatibility, the workflow/task `sticky` field also accepts legacy
|
|
64
|
+
* protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
|
|
65
|
+
*/
|
|
66
|
+
export declare const StickyStrategy: {
|
|
67
|
+
readonly SOFT: "soft";
|
|
68
|
+
readonly HARD: "hard";
|
|
69
|
+
};
|
|
70
|
+
export type StickyStrategy = (typeof StickyStrategy)[keyof typeof StickyStrategy];
|
|
71
|
+
export type StickyStrategyInput = StickyStrategy | 'SOFT' | 'HARD' | 0 | 1;
|
|
54
72
|
export type CreateBaseWorkflowOpts = {
|
|
55
73
|
/**
|
|
56
74
|
* The name of the workflow.
|
|
57
75
|
*/
|
|
58
|
-
name:
|
|
76
|
+
name: string;
|
|
59
77
|
/**
|
|
60
78
|
* (optional) description of the workflow.
|
|
61
79
|
*/
|
|
62
|
-
description?:
|
|
80
|
+
description?: string;
|
|
63
81
|
/**
|
|
64
82
|
* (optional) version of the workflow.
|
|
65
83
|
*/
|
|
66
|
-
version?:
|
|
84
|
+
version?: string;
|
|
67
85
|
/**
|
|
68
86
|
* (optional) sticky strategy for the workflow.
|
|
69
87
|
*/
|
|
70
|
-
sticky?:
|
|
88
|
+
sticky?: StickyStrategyInput;
|
|
71
89
|
/**
|
|
72
90
|
* (optional) on config for the workflow.
|
|
73
|
-
* @
|
|
91
|
+
* @alias for onCrons and onEvents
|
|
74
92
|
*/
|
|
75
|
-
on?:
|
|
93
|
+
on?: {
|
|
94
|
+
cron?: string | string[];
|
|
95
|
+
event?: string | string[];
|
|
96
|
+
};
|
|
76
97
|
/**
|
|
77
98
|
* (optional) cron config for the workflow.
|
|
78
99
|
*/
|
package/v1/declaration.js
CHANGED
|
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.Priority = void 0;
|
|
12
|
+
exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.StickyStrategy = exports.Priority = void 0;
|
|
13
13
|
exports.CreateTaskWorkflow = CreateTaskWorkflow;
|
|
14
14
|
exports.CreateWorkflow = CreateWorkflow;
|
|
15
15
|
exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
|
|
16
|
+
const abort_error_1 = require("../util/abort-error");
|
|
16
17
|
const parent_run_context_vars_1 = require("./parent-run-context-vars");
|
|
17
18
|
const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
|
|
18
19
|
// eslint-disable-next-line no-shadow
|
|
@@ -22,6 +23,17 @@ var Priority;
|
|
|
22
23
|
Priority[Priority["MEDIUM"] = 2] = "MEDIUM";
|
|
23
24
|
Priority[Priority["HIGH"] = 3] = "HIGH";
|
|
24
25
|
})(Priority || (exports.Priority = Priority = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Sticky strategy for workflow scheduling.
|
|
28
|
+
*
|
|
29
|
+
* Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
|
|
30
|
+
* For backwards compatibility, the workflow/task `sticky` field also accepts legacy
|
|
31
|
+
* protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
|
|
32
|
+
*/
|
|
33
|
+
exports.StickyStrategy = {
|
|
34
|
+
SOFT: 'soft',
|
|
35
|
+
HARD: 'hard',
|
|
36
|
+
};
|
|
25
37
|
/**
|
|
26
38
|
* Represents a workflow that can be executed by Hatchet.
|
|
27
39
|
* @template I The input type for the workflow.
|
|
@@ -48,7 +60,18 @@ class BaseWorkflowDeclaration {
|
|
|
48
60
|
if (!parentRunContext && ((options === null || options === void 0 ? void 0 : options.childKey) || (options === null || options === void 0 ? void 0 : options.sticky))) {
|
|
49
61
|
this.client.admin.logger.warn('ignoring childKey or sticky because run is not being spawned from a parent task');
|
|
50
62
|
}
|
|
51
|
-
const
|
|
63
|
+
const inheritedSignal = parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.signal;
|
|
64
|
+
// Precheck: if we're being called from a cancelled parent task, do not enqueue more work.
|
|
65
|
+
// The signal is inherited from the parent task's `ctx.abortController.signal`.
|
|
66
|
+
(0, abort_error_1.throwIfAborted)(inheritedSignal, {
|
|
67
|
+
isTrigger: true,
|
|
68
|
+
context: (parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId)
|
|
69
|
+
? `task run ${parentRunContext.parentTaskRunExternalId}`
|
|
70
|
+
: undefined,
|
|
71
|
+
warn: (message) => this.client.admin.logger.warn(message),
|
|
72
|
+
});
|
|
73
|
+
parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(Array.isArray(input) ? input.length : 1);
|
|
74
|
+
const runOpts = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentTaskRunExternalId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId, childIndex: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
|
|
52
75
|
if (Array.isArray(input)) {
|
|
53
76
|
let resp = [];
|
|
54
77
|
for (let i = 0; i < input.length; i += 500) {
|
|
@@ -74,6 +97,9 @@ class BaseWorkflowDeclaration {
|
|
|
74
97
|
// eslint-disable-next-line no-param-reassign
|
|
75
98
|
ref._standaloneTaskName = _standaloneTaskName;
|
|
76
99
|
}
|
|
100
|
+
// Ensure result subscriptions inherit cancellation if no signal is provided explicitly.
|
|
101
|
+
// eslint-disable-next-line no-param-reassign
|
|
102
|
+
ref.defaultSignal = inheritedSignal;
|
|
77
103
|
res.push(ref);
|
|
78
104
|
});
|
|
79
105
|
return res;
|
|
@@ -82,6 +108,7 @@ class BaseWorkflowDeclaration {
|
|
|
82
108
|
if (_standaloneTaskName) {
|
|
83
109
|
res._standaloneTaskName = _standaloneTaskName;
|
|
84
110
|
}
|
|
111
|
+
res.defaultSignal = inheritedSignal;
|
|
85
112
|
return res;
|
|
86
113
|
});
|
|
87
114
|
}
|
|
@@ -103,6 +130,17 @@ class BaseWorkflowDeclaration {
|
|
|
103
130
|
}
|
|
104
131
|
if (Array.isArray(input)) {
|
|
105
132
|
const refs = yield this.runNoWait(input, options, _standaloneTaskName);
|
|
133
|
+
if (options === null || options === void 0 ? void 0 : options.returnExceptions) {
|
|
134
|
+
const settled = yield Promise.allSettled(refs.map((ref) => ref.result()));
|
|
135
|
+
return settled.map((s) => {
|
|
136
|
+
if (s.status === 'fulfilled')
|
|
137
|
+
return s.value;
|
|
138
|
+
const { reason } = s;
|
|
139
|
+
if (reason instanceof Error)
|
|
140
|
+
return reason;
|
|
141
|
+
return new Error(Array.isArray(reason) ? reason.join('; ') : String(reason));
|
|
142
|
+
});
|
|
143
|
+
}
|
|
106
144
|
return Promise.all(refs.map((ref) => ref.result()));
|
|
107
145
|
}
|
|
108
146
|
const res = yield this.runNoWait(input, options, _standaloneTaskName);
|
|
@@ -119,10 +157,16 @@ class BaseWorkflowDeclaration {
|
|
|
119
157
|
*/
|
|
120
158
|
schedule(enqueueAt, input, options) {
|
|
121
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
var _a;
|
|
122
161
|
if (!this.client) {
|
|
123
162
|
throw UNBOUND_ERR;
|
|
124
163
|
}
|
|
125
|
-
|
|
164
|
+
// If called from within a cancelled parent task, do not enqueue scheduled work.
|
|
165
|
+
(0, abort_error_1.throwIfAborted)((_a = parent_run_context_vars_1.parentRunContextManager.getContext()) === null || _a === void 0 ? void 0 : _a.signal, {
|
|
166
|
+
isTrigger: true,
|
|
167
|
+
warn: (message) => this.client.admin.logger.warn(message),
|
|
168
|
+
});
|
|
169
|
+
const scheduled = this.client.scheduled.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, (options !== null && options !== void 0 ? options : {})));
|
|
126
170
|
return scheduled;
|
|
127
171
|
});
|
|
128
172
|
}
|
|
@@ -152,10 +196,16 @@ class BaseWorkflowDeclaration {
|
|
|
152
196
|
*/
|
|
153
197
|
cron(name, expression, input, options) {
|
|
154
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
var _a;
|
|
155
200
|
if (!this.client) {
|
|
156
201
|
throw UNBOUND_ERR;
|
|
157
202
|
}
|
|
158
|
-
|
|
203
|
+
// If called from within a cancelled parent task, do not enqueue cron work.
|
|
204
|
+
(0, abort_error_1.throwIfAborted)((_a = parent_run_context_vars_1.parentRunContextManager.getContext()) === null || _a === void 0 ? void 0 : _a.signal, {
|
|
205
|
+
isTrigger: true,
|
|
206
|
+
warn: (message) => this.client.admin.logger.warn(message),
|
|
207
|
+
});
|
|
208
|
+
const cronDef = this.client.crons.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, (options !== null && options !== void 0 ? options : {})), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
|
|
159
209
|
return cronDef;
|
|
160
210
|
});
|
|
161
211
|
}
|
|
@@ -283,7 +333,7 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
283
333
|
typedOptions = options;
|
|
284
334
|
}
|
|
285
335
|
if (this.definition.onFailure) {
|
|
286
|
-
(_a = this.client) === null || _a === void 0 ? void 0 : _a.
|
|
336
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.logger.warn(`onFailure task will override existing onFailure task`);
|
|
287
337
|
}
|
|
288
338
|
this.definition.onFailure = typedOptions;
|
|
289
339
|
return typedOptions;
|
|
@@ -306,7 +356,7 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
306
356
|
typedOptions = options;
|
|
307
357
|
}
|
|
308
358
|
if (this.definition.onSuccess) {
|
|
309
|
-
(_a = this.client) === null || _a === void 0 ? void 0 : _a.
|
|
359
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.logger.warn(`onSuccess task will override existing onSuccess task`);
|
|
310
360
|
}
|
|
311
361
|
this.definition.onSuccess = typedOptions;
|
|
312
362
|
return typedOptions;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HatchetClient } from '../..';
|
|
2
|
+
import type { BaseWorkflowDeclaration } from '../..';
|
|
3
|
+
import { Worker } from '../../client/worker/worker';
|
|
4
|
+
export declare function requireEnv(name: string): string;
|
|
5
|
+
export declare function makeE2EClient(): HatchetClient;
|
|
6
|
+
export declare function makeTestScope(prefix?: string): string;
|
|
7
|
+
export declare function startWorker({ client, name, workflows, slots, }: {
|
|
8
|
+
client: HatchetClient;
|
|
9
|
+
name: string;
|
|
10
|
+
workflows: Array<BaseWorkflowDeclaration<any, any>>;
|
|
11
|
+
slots?: number;
|
|
12
|
+
}): Promise<Worker>;
|
|
13
|
+
export declare function stopWorker(worker: Worker | undefined): Promise<void>;
|
|
14
|
+
export declare function poll<T>(fn: () => Promise<T>, { timeoutMs, intervalMs, shouldStop, label, }: {
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
intervalMs?: number;
|
|
17
|
+
shouldStop: (value: T) => boolean;
|
|
18
|
+
label?: string;
|
|
19
|
+
}): Promise<T>;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.requireEnv = requireEnv;
|
|
16
|
+
exports.makeE2EClient = makeE2EClient;
|
|
17
|
+
exports.makeTestScope = makeTestScope;
|
|
18
|
+
exports.startWorker = startWorker;
|
|
19
|
+
exports.stopWorker = stopWorker;
|
|
20
|
+
exports.poll = poll;
|
|
21
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
22
|
+
const crypto_1 = require("crypto");
|
|
23
|
+
const v1_1 = require("../..");
|
|
24
|
+
function requireEnv(name) {
|
|
25
|
+
const value = process.env[name];
|
|
26
|
+
if (!value) {
|
|
27
|
+
throw new Error(`Missing required environment variable ${name}. ` +
|
|
28
|
+
`E2E tests require a configured Hatchet instance and credentials.`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function makeE2EClient() {
|
|
33
|
+
// ConfigLoader requires a token; this makes the failure message obvious.
|
|
34
|
+
requireEnv('HATCHET_CLIENT_TOKEN');
|
|
35
|
+
return v1_1.HatchetClient.init();
|
|
36
|
+
}
|
|
37
|
+
function makeTestScope(prefix = 'ts_e2e') {
|
|
38
|
+
return `${prefix}_${(0, crypto_1.randomUUID)()}`;
|
|
39
|
+
}
|
|
40
|
+
function startWorker(_a) {
|
|
41
|
+
return __awaiter(this, arguments, void 0, function* ({ client, name, workflows, slots = 50, }) {
|
|
42
|
+
const worker = yield client.worker(name, { workflows, slots });
|
|
43
|
+
void worker.start();
|
|
44
|
+
yield worker.waitUntilReady(10000);
|
|
45
|
+
return worker;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function stopWorker(worker) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!worker)
|
|
51
|
+
return;
|
|
52
|
+
yield worker.stop();
|
|
53
|
+
yield (0, sleep_1.default)(300);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function poll(fn_1, _a) {
|
|
57
|
+
return __awaiter(this, arguments, void 0, function* (fn, { timeoutMs = 30000, intervalMs = 100, shouldStop, label = 'poll', }) {
|
|
58
|
+
const start = Date.now();
|
|
59
|
+
// eslint-disable-next-line no-constant-condition
|
|
60
|
+
while (true) {
|
|
61
|
+
const value = yield fn();
|
|
62
|
+
if (shouldStop(value))
|
|
63
|
+
return value;
|
|
64
|
+
if (Date.now() - start > timeoutMs) {
|
|
65
|
+
throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
|
|
66
|
+
}
|
|
67
|
+
yield (0, sleep_1.default)(intervalMs);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const v1_1 = require("../..");
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
14
|
// > AffinityWorkflow
|
|
15
15
|
const workflow = hatchet_client_1.hatchet.workflow({
|
|
@@ -22,8 +22,8 @@ workflow.task({
|
|
|
22
22
|
const results = [];
|
|
23
23
|
// eslint-disable-next-line no-plusplus
|
|
24
24
|
for (let i = 0; i < 50; i++) {
|
|
25
|
-
const result = yield
|
|
26
|
-
results.push(result
|
|
25
|
+
const result = yield childWorkflow.run({});
|
|
26
|
+
results.push(result);
|
|
27
27
|
}
|
|
28
28
|
console.log('Spawned 50 child workflows');
|
|
29
29
|
console.log('Results:', yield Promise.all(results));
|
|
@@ -55,7 +55,7 @@ childWorkflow.task({
|
|
|
55
55
|
memory: {
|
|
56
56
|
value: 512,
|
|
57
57
|
required: true,
|
|
58
|
-
comparator:
|
|
58
|
+
comparator: v1_1.WorkerLabelComparator.LESS_THAN,
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ParentInput = {
|
|
2
|
+
n: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const bulkChild: import("../..").TaskWorkflowDeclaration<{
|
|
5
|
+
i: number;
|
|
6
|
+
}, {
|
|
7
|
+
i: number;
|
|
8
|
+
}, {}, {}, {}, {}>;
|
|
9
|
+
export declare const bulkParentWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.bulkParentWorkflow = exports.bulkChild = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
exports.bulkChild = hatchet_client_1.hatchet.task({
|
|
15
|
+
name: 'bulk-child',
|
|
16
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
return { i: input.i };
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
exports.bulkParentWorkflow = hatchet_client_1.hatchet.workflow({
|
|
21
|
+
name: 'bulk-parent',
|
|
22
|
+
});
|
|
23
|
+
exports.bulkParentWorkflow.task({
|
|
24
|
+
name: 'spawn',
|
|
25
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const typed = input;
|
|
27
|
+
const children = Array.from({ length: typed.n }, (_, i) => ({
|
|
28
|
+
workflow: exports.bulkChild,
|
|
29
|
+
input: { i },
|
|
30
|
+
}));
|
|
31
|
+
const results = yield ctx.bulkRunChildren(children);
|
|
32
|
+
return { results };
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const bulkReplayTest1: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
|
|
2
|
+
export declare const bulkReplayTest2: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
|
|
3
|
+
export declare const bulkReplayTest3: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
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.bulkReplayTest3 = exports.bulkReplayTest2 = exports.bulkReplayTest1 = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
exports.bulkReplayTest1 = hatchet_client_1.hatchet.task({
|
|
16
|
+
name: 'bulk-replay-test-1',
|
|
17
|
+
retries: 1,
|
|
18
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
console.log('retrying bulk replay test task', ctx.retryCount());
|
|
20
|
+
if (ctx.retryCount() === 0) {
|
|
21
|
+
throw new Error('This is a test error to trigger a retry.');
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
exports.bulkReplayTest2 = hatchet_client_1.hatchet.task({
|
|
26
|
+
name: 'bulk-replay-test-2',
|
|
27
|
+
retries: 1,
|
|
28
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
console.log('retrying bulk replay test task', ctx.retryCount());
|
|
30
|
+
if (ctx.retryCount() === 0) {
|
|
31
|
+
throw new Error('This is a test error to trigger a retry.');
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
exports.bulkReplayTest3 = hatchet_client_1.hatchet.task({
|
|
36
|
+
name: 'bulk-replay-test-3',
|
|
37
|
+
retries: 1,
|
|
38
|
+
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
console.log('retrying bulk replay test task', ctx.retryCount());
|
|
40
|
+
if (ctx.retryCount() === 0) {
|
|
41
|
+
throw new Error('This is a test error to trigger a retry.');
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
});
|