@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,7 +1,7 @@
|
|
|
1
1
|
import { CronWorkflows, CronWorkflowsList } from '../../../clients/rest/generated/data-contracts';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Workflow } from '../../../workflow';
|
|
4
3
|
import { BaseWorkflowDeclaration } from '../..';
|
|
4
|
+
import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
|
|
5
5
|
import { HatchetClient } from '../client';
|
|
6
6
|
import { WorkflowsClient } from './workflows';
|
|
7
7
|
/**
|
|
@@ -52,7 +52,7 @@ export declare class CronClient {
|
|
|
52
52
|
* @returns A promise that resolves to the created CronWorkflows object.
|
|
53
53
|
* @throws Will throw an error if the input is invalid or the API call fails.
|
|
54
54
|
*/
|
|
55
|
-
create(workflow: string |
|
|
55
|
+
create(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow, cron: CreateCronInput): Promise<CronWorkflows>;
|
|
56
56
|
/**
|
|
57
57
|
* Deletes an existing Cron Trigger.
|
|
58
58
|
* @param cron - The Cron Trigger ID as a string or CronWorkflows object.
|
|
@@ -65,7 +65,7 @@ export declare class CronClient {
|
|
|
65
65
|
* @returns A promise that resolves to a CronWorkflowsList object.
|
|
66
66
|
*/
|
|
67
67
|
list(query: Parameters<typeof this.api.cronWorkflowList>[1] & {
|
|
68
|
-
workflow?: string |
|
|
68
|
+
workflow?: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow;
|
|
69
69
|
}): Promise<CronWorkflowsList>;
|
|
70
70
|
/**
|
|
71
71
|
* Retrieves a specific Cron Trigger by its ID.
|
|
@@ -68,7 +68,7 @@ class CronClient {
|
|
|
68
68
|
create(workflow, cron) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
70
|
var _a, _b, _c;
|
|
71
|
-
const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
|
|
71
|
+
const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace).toLowerCase();
|
|
72
72
|
// Validate cron input with zod schema
|
|
73
73
|
try {
|
|
74
74
|
const parsedCron = exports.CreateCronTriggerSchema.parse(cron);
|
|
@@ -112,7 +112,7 @@ class CronClient {
|
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
113
|
const { workflow } = query, rest = __rest(query, ["workflow"]);
|
|
114
114
|
if (workflow) {
|
|
115
|
-
const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
|
|
115
|
+
const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace).toLowerCase());
|
|
116
116
|
rest.workflowId = workflowId;
|
|
117
117
|
}
|
|
118
118
|
const response = yield this.api.cronWorkflowList(this.tenantId, rest);
|
|
@@ -73,7 +73,7 @@ class ScheduleClient {
|
|
|
73
73
|
create(workflow, cron) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
75
|
var _a, _b, _c;
|
|
76
|
-
const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
|
|
76
|
+
const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace).toLowerCase();
|
|
77
77
|
// Validate cron input with zod schema
|
|
78
78
|
try {
|
|
79
79
|
const parsedCron = exports.CreateScheduledRunTriggerSchema.parse(cron);
|
|
@@ -144,7 +144,7 @@ class ScheduleClient {
|
|
|
144
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
145
|
const { workflow } = query, rest = __rest(query, ["workflow"]);
|
|
146
146
|
if (workflow) {
|
|
147
|
-
const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
|
|
147
|
+
const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace).toLowerCase());
|
|
148
148
|
rest.workflowId = workflowId;
|
|
149
149
|
}
|
|
150
150
|
const response = yield this.api.workflowScheduledList(this.tenantId, rest);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Workflow } from '../../../workflow';
|
|
2
1
|
import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
|
|
2
|
+
import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
|
|
3
3
|
import { HatchetClient } from '../client';
|
|
4
|
-
export declare const workflowNameString: (workflow: string |
|
|
4
|
+
export declare const workflowNameString: (workflow: string | WorkflowDefinition | BaseWorkflowDeclaration<any, any> | LegacyWorkflow) => string;
|
|
5
5
|
/**
|
|
6
6
|
* WorkflowsClient is used to list and manage workflows
|
|
7
7
|
*/
|
|
@@ -17,8 +17,8 @@ export declare class WorkflowsClient {
|
|
|
17
17
|
* @param workflow - The workflow name, ID, or object.
|
|
18
18
|
* @returns The workflow ID as a string.
|
|
19
19
|
*/
|
|
20
|
-
getWorkflowIdFromName(workflow: string |
|
|
21
|
-
get(workflow: string | BaseWorkflowDeclaration<any, any> |
|
|
20
|
+
getWorkflowIdFromName(workflow: string | WorkflowDefinition | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<string>;
|
|
21
|
+
get(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<import("../../../clients/rest/generated/data-contracts").Workflow>;
|
|
22
22
|
list(opts?: Parameters<typeof this.api.workflowList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowList>;
|
|
23
|
-
delete(workflow: string | BaseWorkflowDeclaration<any, any> |
|
|
23
|
+
delete(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<void>;
|
|
24
24
|
}
|
|
@@ -10,15 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.WorkflowsClient = exports.workflowNameString = void 0;
|
|
13
|
+
const legacy_transformer_1 = require("../../../legacy/legacy-transformer");
|
|
13
14
|
const uuid_1 = require("../../../util/uuid");
|
|
14
15
|
const workflowNameString = (workflow) => {
|
|
15
16
|
if (typeof workflow === 'string') {
|
|
16
17
|
return workflow;
|
|
17
18
|
}
|
|
18
|
-
if (typeof workflow === 'object' && '
|
|
19
|
+
if (typeof workflow === 'object' && 'name' in workflow) {
|
|
20
|
+
return workflow.name;
|
|
21
|
+
}
|
|
22
|
+
if ((0, legacy_transformer_1.isLegacyWorkflow)(workflow)) {
|
|
23
|
+
(0, legacy_transformer_1.warnLegacyWorkflow)();
|
|
19
24
|
return workflow.id;
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
throw new Error('Invalid workflow: must be a string, Workflow object, or WorkflowDefinition object');
|
|
22
27
|
};
|
|
23
28
|
exports.workflowNameString = workflowNameString;
|
|
24
29
|
/**
|
|
@@ -52,12 +57,6 @@ class WorkflowsClient {
|
|
|
52
57
|
if (typeof workflow === 'object' && 'name' in workflow) {
|
|
53
58
|
return workflow.name;
|
|
54
59
|
}
|
|
55
|
-
if (typeof workflow === 'object' && 'id' in workflow) {
|
|
56
|
-
if (!workflow.id) {
|
|
57
|
-
throw new Error('Workflow ID is required');
|
|
58
|
-
}
|
|
59
|
-
return workflow.id;
|
|
60
|
-
}
|
|
61
60
|
throw new Error('Invalid workflow: must be a string, Workflow object, or WorkflowDefinition object');
|
|
62
61
|
})();
|
|
63
62
|
if (!(0, uuid_1.isValidUUID)(str)) {
|
|
@@ -6,10 +6,10 @@ import WorkflowRunRef from '../../../util/workflow-run-ref';
|
|
|
6
6
|
import { Conditions } from '../../conditions';
|
|
7
7
|
import { CreateWorkflowDurableTaskOpts, CreateWorkflowTaskOpts } from '../../task';
|
|
8
8
|
import { OutputType } from '../../types';
|
|
9
|
-
import { Workflow } from '../../../workflow';
|
|
10
9
|
import { HatchetClient } from '../..';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
|
|
11
|
+
import { NextStep } from '../../../legacy/step';
|
|
12
|
+
import { InternalWorker } from './worker-internal';
|
|
13
13
|
import { Duration } from '../duration';
|
|
14
14
|
type TriggerData = Record<string, Record<string, any>>;
|
|
15
15
|
type ChildRunOpts = RunOpts & {
|
|
@@ -28,6 +28,35 @@ interface ContextData<T, K> {
|
|
|
28
28
|
user_data: K;
|
|
29
29
|
step_run_errors: Record<string, string>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* ContextWorker is a wrapper around the V1Worker class that provides a more user-friendly interface for the worker from the context of a run.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ContextWorker {
|
|
35
|
+
private worker;
|
|
36
|
+
constructor(worker: InternalWorker);
|
|
37
|
+
/**
|
|
38
|
+
* Gets the ID of the worker.
|
|
39
|
+
* @returns The ID of the worker.
|
|
40
|
+
*/
|
|
41
|
+
id(): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the worker has a registered workflow.
|
|
44
|
+
* @param workflowName - The name of the workflow to check.
|
|
45
|
+
* @returns True if the workflow is registered, otherwise false.
|
|
46
|
+
*/
|
|
47
|
+
hasWorkflow(workflowName: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the current state of the worker labels.
|
|
50
|
+
* @returns The labels of the worker.
|
|
51
|
+
*/
|
|
52
|
+
labels(): WorkerLabels;
|
|
53
|
+
/**
|
|
54
|
+
* Upserts the a set of labels on the worker.
|
|
55
|
+
* @param labels - The labels to upsert.
|
|
56
|
+
* @returns A promise that resolves when the labels have been upserted.
|
|
57
|
+
*/
|
|
58
|
+
upsertLabels(labels: WorkerLabels): Promise<WorkerLabels>;
|
|
59
|
+
}
|
|
31
60
|
export declare class Context<T, K = {}> {
|
|
32
61
|
data: ContextData<T, K>;
|
|
33
62
|
input: T;
|
|
@@ -39,9 +68,19 @@ export declare class Context<T, K = {}> {
|
|
|
39
68
|
_logger: Logger;
|
|
40
69
|
spawnIndex: number;
|
|
41
70
|
streamIndex: number;
|
|
42
|
-
constructor(action: Action, v1: HatchetClient, worker:
|
|
71
|
+
constructor(action: Action, v1: HatchetClient, worker: InternalWorker);
|
|
43
72
|
get abortController(): AbortController;
|
|
44
73
|
get cancelled(): boolean;
|
|
74
|
+
protected throwIfCancelled(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Helper for broad `catch` blocks so cancellation isn't accidentally swallowed.
|
|
77
|
+
*
|
|
78
|
+
* Example:
|
|
79
|
+
* ```ts
|
|
80
|
+
* try { ... } catch (e) { ctx.rethrowIfCancelled(e); ... }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
rethrowIfCancelled(err: unknown): void;
|
|
45
84
|
cancel(): Promise<void>;
|
|
46
85
|
/**
|
|
47
86
|
* Retrieves the output of a parent task.
|
|
@@ -165,7 +204,7 @@ export declare class Context<T, K = {}> {
|
|
|
165
204
|
* @returns A list of workflow run references to the enqueued runs.
|
|
166
205
|
*/
|
|
167
206
|
bulkRunNoWaitChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
168
|
-
workflow: string |
|
|
207
|
+
workflow: string | WorkflowV1<Q, P>;
|
|
169
208
|
input: Q;
|
|
170
209
|
options?: ChildRunOpts;
|
|
171
210
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
@@ -175,7 +214,7 @@ export declare class Context<T, K = {}> {
|
|
|
175
214
|
* @returns A list of results from the children workflows.
|
|
176
215
|
*/
|
|
177
216
|
bulkRunChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
178
|
-
workflow: string |
|
|
217
|
+
workflow: string | WorkflowV1<Q, P>;
|
|
179
218
|
input: Q;
|
|
180
219
|
options?: ChildRunOpts;
|
|
181
220
|
}>): Promise<P[]>;
|
|
@@ -187,7 +226,7 @@ export declare class Context<T, K = {}> {
|
|
|
187
226
|
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
188
227
|
* @returns The result of the workflow.
|
|
189
228
|
*/
|
|
190
|
-
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string |
|
|
229
|
+
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<P>;
|
|
191
230
|
/**
|
|
192
231
|
* Enqueues a new workflow without waiting for its result.
|
|
193
232
|
*
|
|
@@ -196,7 +235,7 @@ export declare class Context<T, K = {}> {
|
|
|
196
235
|
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
197
236
|
* @returns A reference to the spawned workflow run.
|
|
198
237
|
*/
|
|
199
|
-
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string |
|
|
238
|
+
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | WorkflowV1<Q, P>, input: Q, options?: ChildRunOpts): Promise<WorkflowRunRef<P>>;
|
|
200
239
|
/**
|
|
201
240
|
* Retrieves additional metadata associated with the current workflow run.
|
|
202
241
|
* @returns A record of metadata key-value pairs.
|
|
@@ -246,7 +285,7 @@ export declare class Context<T, K = {}> {
|
|
|
246
285
|
* @deprecated Use bulkRunNoWaitChildren or bulkRunChildren instead.
|
|
247
286
|
*/
|
|
248
287
|
spawnWorkflows<Q extends JsonObject = any, P extends JsonObject = any>(workflows: Array<{
|
|
249
|
-
workflow: string |
|
|
288
|
+
workflow: string | WorkflowV1<Q, P>;
|
|
250
289
|
input: Q;
|
|
251
290
|
options?: ChildRunOpts;
|
|
252
291
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
@@ -259,7 +298,7 @@ export declare class Context<T, K = {}> {
|
|
|
259
298
|
* @returns A reference to the spawned workflow run.
|
|
260
299
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
261
300
|
*/
|
|
262
|
-
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string |
|
|
301
|
+
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<WorkflowRunRef<P>>;
|
|
263
302
|
_incrementStreamIndex(): number;
|
|
264
303
|
}
|
|
265
304
|
export declare class DurableContext<T, K = {}> extends Context<T, K> {
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DurableContext = exports.Context = void 0;
|
|
15
|
+
exports.DurableContext = exports.Context = exports.ContextWorker = void 0;
|
|
16
16
|
/* eslint-disable no-underscore-dangle */
|
|
17
17
|
/* eslint-disable max-classes-per-file */
|
|
18
18
|
const declaration_1 = require("../../declaration");
|
|
@@ -21,8 +21,47 @@ const parse_1 = require("../../../util/parse");
|
|
|
21
21
|
const conditions_1 = require("../../conditions");
|
|
22
22
|
const transformer_1 = require("../../conditions/transformer");
|
|
23
23
|
const condition_1 = require("../../../protoc/v1/shared/condition");
|
|
24
|
-
const step_1 = require("../../../step");
|
|
25
24
|
const apply_namespace_1 = require("../../../util/apply-namespace");
|
|
25
|
+
const abort_error_1 = require("../../../util/abort-error");
|
|
26
|
+
/**
|
|
27
|
+
* ContextWorker is a wrapper around the V1Worker class that provides a more user-friendly interface for the worker from the context of a run.
|
|
28
|
+
*/
|
|
29
|
+
class ContextWorker {
|
|
30
|
+
constructor(worker) {
|
|
31
|
+
this.worker = worker;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gets the ID of the worker.
|
|
35
|
+
* @returns The ID of the worker.
|
|
36
|
+
*/
|
|
37
|
+
id() {
|
|
38
|
+
return this.worker.workerId;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the worker has a registered workflow.
|
|
42
|
+
* @param workflowName - The name of the workflow to check.
|
|
43
|
+
* @returns True if the workflow is registered, otherwise false.
|
|
44
|
+
*/
|
|
45
|
+
hasWorkflow(workflowName) {
|
|
46
|
+
return !!this.worker.workflow_registry.find((workflow) => 'id' in workflow ? workflow.id === workflowName : workflow.name === workflowName);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the current state of the worker labels.
|
|
50
|
+
* @returns The labels of the worker.
|
|
51
|
+
*/
|
|
52
|
+
labels() {
|
|
53
|
+
return this.worker.labels;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Upserts the a set of labels on the worker.
|
|
57
|
+
* @param labels - The labels to upsert.
|
|
58
|
+
* @returns A promise that resolves when the labels have been upserted.
|
|
59
|
+
*/
|
|
60
|
+
upsertLabels(labels) {
|
|
61
|
+
return this.worker.upsertLabels(labels);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ContextWorker = ContextWorker;
|
|
26
65
|
class Context {
|
|
27
66
|
constructor(action, v1, worker) {
|
|
28
67
|
// @deprecated use ctx.abortController instead
|
|
@@ -35,7 +74,7 @@ class Context {
|
|
|
35
74
|
this.data = data;
|
|
36
75
|
this.action = action;
|
|
37
76
|
this.v1 = v1;
|
|
38
|
-
this.worker = new
|
|
77
|
+
this.worker = new ContextWorker(worker);
|
|
39
78
|
this._logger = v1.config.logger(`Context Logger`, v1.config.log_level);
|
|
40
79
|
// if this is a getGroupKeyRunId, the data is the workflow input
|
|
41
80
|
if (action.getGroupKeyRunId !== '') {
|
|
@@ -56,6 +95,22 @@ class Context {
|
|
|
56
95
|
get cancelled() {
|
|
57
96
|
return this.controller.signal.aborted;
|
|
58
97
|
}
|
|
98
|
+
throwIfCancelled() {
|
|
99
|
+
if (this.abortController.signal.aborted) {
|
|
100
|
+
throw (0, abort_error_1.createAbortError)('Operation cancelled by AbortSignal');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Helper for broad `catch` blocks so cancellation isn't accidentally swallowed.
|
|
105
|
+
*
|
|
106
|
+
* Example:
|
|
107
|
+
* ```ts
|
|
108
|
+
* try { ... } catch (e) { ctx.rethrowIfCancelled(e); ... }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
rethrowIfCancelled(err) {
|
|
112
|
+
(0, abort_error_1.rethrowIfAborted)(err);
|
|
113
|
+
}
|
|
59
114
|
cancel() {
|
|
60
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
116
|
yield this.v1.runs.cancel({
|
|
@@ -263,7 +318,7 @@ class Context {
|
|
|
263
318
|
this._logger.warn('cannot refresh timeout from context without stepRunId');
|
|
264
319
|
return;
|
|
265
320
|
}
|
|
266
|
-
yield this.v1.
|
|
321
|
+
yield this.v1.dispatcher.refreshTimeout(incrementBy, taskRunExternalId);
|
|
267
322
|
});
|
|
268
323
|
}
|
|
269
324
|
/**
|
|
@@ -273,7 +328,7 @@ class Context {
|
|
|
273
328
|
*/
|
|
274
329
|
releaseSlot() {
|
|
275
330
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
yield this.v1.
|
|
331
|
+
yield this.v1.dispatcher.client.releaseSlot({
|
|
277
332
|
taskRunExternalId: this.action.taskRunExternalId,
|
|
278
333
|
});
|
|
279
334
|
});
|
|
@@ -292,16 +347,17 @@ class Context {
|
|
|
292
347
|
return;
|
|
293
348
|
}
|
|
294
349
|
const index = this._incrementStreamIndex();
|
|
295
|
-
yield this.v1.
|
|
350
|
+
yield this.v1.events.putStream(taskRunExternalId, data, index);
|
|
296
351
|
});
|
|
297
352
|
}
|
|
298
353
|
spawnOptions(workflow, options) {
|
|
354
|
+
this.throwIfCancelled();
|
|
299
355
|
let workflowName;
|
|
300
356
|
if (typeof workflow === 'string') {
|
|
301
357
|
workflowName = workflow;
|
|
302
358
|
}
|
|
303
359
|
else {
|
|
304
|
-
workflowName = workflow.
|
|
360
|
+
workflowName = workflow.name;
|
|
305
361
|
}
|
|
306
362
|
const opts = options || {};
|
|
307
363
|
const { sticky } = opts;
|
|
@@ -309,7 +365,7 @@ class Context {
|
|
|
309
365
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${workflowName} is not registered on the worker`);
|
|
310
366
|
}
|
|
311
367
|
const { workflowRunId, taskRunExternalId } = this.action;
|
|
312
|
-
const finalOpts = Object.assign(Object.assign({},
|
|
368
|
+
const finalOpts = Object.assign(Object.assign({}, opts), { parentId: workflowRunId, parentTaskRunExternalId: taskRunExternalId, childIndex: this.spawnIndex, childKey: options === null || options === void 0 ? void 0 : options.key, desiredWorkerId: sticky ? this.worker.id() : undefined, _standaloneTaskName: workflow instanceof declaration_1.TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined });
|
|
313
369
|
this.spawnIndex += 1;
|
|
314
370
|
return { workflowName, opts: finalOpts };
|
|
315
371
|
}
|
|
@@ -318,6 +374,7 @@ class Context {
|
|
|
318
374
|
return this.v1.admin.runWorkflow(workflowName, input, opts);
|
|
319
375
|
}
|
|
320
376
|
spawnBulk(children) {
|
|
377
|
+
this.throwIfCancelled();
|
|
321
378
|
const workflows = children.map((child) => {
|
|
322
379
|
const { workflowName, opts } = this.spawnOptions(child.workflow, child.options);
|
|
323
380
|
return { workflowName, input: child.input, options: opts };
|
|
@@ -331,7 +388,12 @@ class Context {
|
|
|
331
388
|
*/
|
|
332
389
|
bulkRunNoWaitChildren(children) {
|
|
333
390
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
-
|
|
391
|
+
const refs = yield this.spawnBulk(children);
|
|
392
|
+
refs.forEach((ref) => {
|
|
393
|
+
// eslint-disable-next-line no-param-reassign
|
|
394
|
+
ref.defaultSignal = this.abortController.signal;
|
|
395
|
+
});
|
|
396
|
+
return refs;
|
|
335
397
|
});
|
|
336
398
|
}
|
|
337
399
|
/**
|
|
@@ -356,6 +418,9 @@ class Context {
|
|
|
356
418
|
runChild(workflow, input, options) {
|
|
357
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
358
420
|
const run = yield this.spawn(workflow, input, options);
|
|
421
|
+
// Ensure waiting for the child result aborts when this task is cancelled.
|
|
422
|
+
// eslint-disable-next-line no-param-reassign
|
|
423
|
+
run.defaultSignal = this.abortController.signal;
|
|
359
424
|
return run.output;
|
|
360
425
|
});
|
|
361
426
|
}
|
|
@@ -370,6 +435,7 @@ class Context {
|
|
|
370
435
|
runNoWaitChild(workflow, input, options) {
|
|
371
436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
372
437
|
const ref = yield this.spawn(workflow, input, options);
|
|
438
|
+
ref.defaultSignal = this.abortController.signal;
|
|
373
439
|
return ref;
|
|
374
440
|
});
|
|
375
441
|
}
|
|
@@ -460,6 +526,7 @@ class Context {
|
|
|
460
526
|
*/
|
|
461
527
|
spawnWorkflows(workflows) {
|
|
462
528
|
return __awaiter(this, void 0, void 0, function* () {
|
|
529
|
+
this.throwIfCancelled();
|
|
463
530
|
const { workflowRunId, taskRunExternalId } = this.action;
|
|
464
531
|
const workflowRuns = workflows.map(({ workflow, input, options }) => {
|
|
465
532
|
let workflowName;
|
|
@@ -467,18 +534,22 @@ class Context {
|
|
|
467
534
|
workflowName = workflow;
|
|
468
535
|
}
|
|
469
536
|
else {
|
|
470
|
-
workflowName = workflow.
|
|
537
|
+
workflowName = workflow.name;
|
|
471
538
|
}
|
|
472
|
-
const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace);
|
|
539
|
+
const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace).toLowerCase();
|
|
473
540
|
const opts = options || {};
|
|
474
541
|
const { sticky } = opts;
|
|
475
542
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
476
543
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
477
544
|
}
|
|
545
|
+
// `signal` must never be sent over the wire.
|
|
546
|
+
const optsWithoutSignal = Object.assign({}, opts);
|
|
547
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
548
|
+
delete optsWithoutSignal.signal;
|
|
478
549
|
const resp = {
|
|
479
550
|
workflowName: name,
|
|
480
551
|
input,
|
|
481
|
-
options: Object.assign(Object.assign({},
|
|
552
|
+
options: Object.assign(Object.assign({}, optsWithoutSignal), { parentId: workflowRunId, parentTaskRunExternalId: taskRunExternalId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }),
|
|
482
553
|
};
|
|
483
554
|
this.spawnIndex += 1;
|
|
484
555
|
return resp;
|
|
@@ -488,7 +559,7 @@ class Context {
|
|
|
488
559
|
let resp = [];
|
|
489
560
|
for (let i = 0; i < workflowRuns.length; i += batchSize) {
|
|
490
561
|
const batch = workflowRuns.slice(i, i + batchSize);
|
|
491
|
-
const batchResp = yield this.v1.
|
|
562
|
+
const batchResp = yield this.v1.admin.runWorkflows(batch);
|
|
492
563
|
resp = resp.concat(batchResp);
|
|
493
564
|
}
|
|
494
565
|
const res = [];
|
|
@@ -518,22 +589,23 @@ class Context {
|
|
|
518
589
|
*/
|
|
519
590
|
spawnWorkflow(workflow, input, options) {
|
|
520
591
|
return __awaiter(this, void 0, void 0, function* () {
|
|
592
|
+
this.throwIfCancelled();
|
|
521
593
|
const { workflowRunId, taskRunExternalId } = this.action;
|
|
522
594
|
let workflowName = '';
|
|
523
595
|
if (typeof workflow === 'string') {
|
|
524
596
|
workflowName = workflow;
|
|
525
597
|
}
|
|
526
598
|
else {
|
|
527
|
-
workflowName = workflow.
|
|
599
|
+
workflowName = workflow.name;
|
|
528
600
|
}
|
|
529
|
-
const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace);
|
|
601
|
+
const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace).toLowerCase();
|
|
530
602
|
const opts = options || {};
|
|
531
603
|
const { sticky } = opts;
|
|
532
604
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
533
605
|
throw new hatchet_error_1.default(`cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
534
606
|
}
|
|
535
607
|
try {
|
|
536
|
-
const resp = yield this.v1.
|
|
608
|
+
const resp = yield this.v1.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentTaskRunExternalId: taskRunExternalId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
|
|
537
609
|
this.spawnIndex += 1;
|
|
538
610
|
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
539
611
|
resp._standaloneTaskName = workflow._standalone_task_name;
|
|
@@ -576,20 +648,20 @@ class DurableContext extends Context {
|
|
|
576
648
|
*/
|
|
577
649
|
waitFor(conditions) {
|
|
578
650
|
return __awaiter(this, void 0, void 0, function* () {
|
|
651
|
+
this.throwIfCancelled();
|
|
579
652
|
const pbConditions = (0, transformer_1.conditionsToPb)((0, conditions_1.Render)(condition_1.Action.CREATE, conditions));
|
|
580
653
|
// eslint-disable-next-line no-plusplus
|
|
581
654
|
const key = `waitFor-${this.waitKey++}`;
|
|
582
|
-
yield this.v1.
|
|
655
|
+
yield this.v1.durableListener.registerDurableEvent({
|
|
583
656
|
taskId: this.action.taskRunExternalId,
|
|
584
657
|
signalKey: key,
|
|
585
658
|
sleepConditions: pbConditions.sleepConditions,
|
|
586
659
|
userEventConditions: pbConditions.userEventConditions,
|
|
587
660
|
});
|
|
588
|
-
const
|
|
661
|
+
const event = yield this.v1.durableListener.result({
|
|
589
662
|
taskId: this.action.taskRunExternalId,
|
|
590
663
|
signalKey: key,
|
|
591
|
-
});
|
|
592
|
-
const event = yield listener.get();
|
|
664
|
+
}, { signal: this.abortController.signal });
|
|
593
665
|
// Convert event.data from Uint8Array to string if needed
|
|
594
666
|
const eventData = event.data instanceof Uint8Array ? new TextDecoder().decode(event.data) : event.data;
|
|
595
667
|
const res = JSON.parse(eventData);
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ActionListener } from '../../../../clients/dispatcher/action-listener';
|
|
6
6
|
import { HatchetClient } from '../../..';
|
|
7
|
-
import {
|
|
8
|
-
export declare class LegacyV1Worker extends
|
|
7
|
+
import { InternalWorker } from '../worker-internal';
|
|
8
|
+
export declare class LegacyV1Worker extends InternalWorker {
|
|
9
9
|
private _legacySlotCount;
|
|
10
|
-
constructor(client: HatchetClient, options: ConstructorParameters<typeof
|
|
10
|
+
constructor(client: HatchetClient, options: ConstructorParameters<typeof InternalWorker>[1], legacySlots: number);
|
|
11
11
|
/**
|
|
12
12
|
* Override registration to use the legacy `slots` proto field.
|
|
13
13
|
*/
|
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.LegacyV1Worker = void 0;
|
|
17
17
|
const worker_internal_1 = require("../worker-internal");
|
|
18
18
|
const legacy_registration_1 = require("./legacy-registration");
|
|
19
|
-
class LegacyV1Worker extends worker_internal_1.
|
|
19
|
+
class LegacyV1Worker extends worker_internal_1.InternalWorker {
|
|
20
20
|
constructor(client, options, legacySlots) {
|
|
21
21
|
super(client, options);
|
|
22
22
|
this._legacySlotCount = legacySlots;
|
|
@@ -26,7 +26,7 @@ class LegacyV1Worker extends worker_internal_1.V1Worker {
|
|
|
26
26
|
*/
|
|
27
27
|
createListener() {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
return (0, legacy_registration_1.legacyGetActionListener)(this.client.
|
|
29
|
+
return (0, legacy_registration_1.legacyGetActionListener)(this.client.dispatcher, {
|
|
30
30
|
workerName: this.name,
|
|
31
31
|
services: ['default'],
|
|
32
32
|
actions: Object.keys(this.action_registry),
|
|
@@ -18,10 +18,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.LegacyDualWorker = void 0;
|
|
20
20
|
exports.isLegacyEngine = isLegacyEngine;
|
|
21
|
+
/* eslint-disable no-underscore-dangle */
|
|
21
22
|
const nice_grpc_1 = require("nice-grpc");
|
|
22
23
|
const declaration_1 = require("../../../declaration");
|
|
23
24
|
const legacy_v1_worker_1 = require("./legacy-v1-worker");
|
|
24
25
|
const deprecation_1 = require("./deprecation");
|
|
26
|
+
const legacy_transformer_1 = require("../../../../legacy/legacy-transformer");
|
|
25
27
|
const DEFAULT_DEFAULT_SLOTS = 100;
|
|
26
28
|
const DEFAULT_DURABLE_SLOTS = 1000;
|
|
27
29
|
/** The date when slot_config support was released. */
|
|
@@ -40,10 +42,10 @@ const LEGACY_ENGINE_MESSAGE = 'Connected to an older Hatchet engine that does no
|
|
|
40
42
|
function isLegacyEngine(v1) {
|
|
41
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
44
|
try {
|
|
43
|
-
const version = yield v1.
|
|
45
|
+
const version = yield v1.dispatcher.getVersion();
|
|
44
46
|
// If the version is empty or older than the minimum, treat as legacy
|
|
45
47
|
if (!version || (0, deprecation_1.semverLessThan)(version, MIN_SLOT_CONFIG_VERSION)) {
|
|
46
|
-
const logger = v1.
|
|
48
|
+
const logger = v1.config.logger('Worker', v1.config.log_level);
|
|
47
49
|
(0, deprecation_1.emitDeprecationNotice)('legacy-engine', LEGACY_ENGINE_MESSAGE, LEGACY_ENGINE_START, logger, {
|
|
48
50
|
errorDays: 180,
|
|
49
51
|
});
|
|
@@ -53,7 +55,7 @@ function isLegacyEngine(v1) {
|
|
|
53
55
|
}
|
|
54
56
|
catch (e) {
|
|
55
57
|
if ((e === null || e === void 0 ? void 0 : e.code) === nice_grpc_1.Status.UNIMPLEMENTED) {
|
|
56
|
-
const logger = v1.
|
|
58
|
+
const logger = v1.config.logger('Worker', v1.config.log_level);
|
|
57
59
|
(0, deprecation_1.emitDeprecationNotice)('legacy-engine', LEGACY_ENGINE_MESSAGE, LEGACY_ENGINE_START, logger, {
|
|
58
60
|
errorDays: 180,
|
|
59
61
|
});
|
|
@@ -105,16 +107,16 @@ class LegacyDualWorker {
|
|
|
105
107
|
for (const wf of options.workflows || []) {
|
|
106
108
|
if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
|
|
107
109
|
if (wf.definition._durableTasks.length > 0 && durableWorker) {
|
|
108
|
-
yield durableWorker.
|
|
109
|
-
durableWorker.
|
|
110
|
+
yield durableWorker.registerWorkflow(wf);
|
|
111
|
+
durableWorker.registerDurableActions(wf.definition);
|
|
110
112
|
}
|
|
111
113
|
else {
|
|
112
|
-
yield nonDurable.
|
|
114
|
+
yield nonDurable.registerWorkflow(wf);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
else {
|
|
116
118
|
// fallback to v0 client for backwards compatibility
|
|
117
|
-
yield nonDurable.registerWorkflow(wf);
|
|
119
|
+
yield nonDurable.registerWorkflow((0, legacy_transformer_1.transformLegacyWorkflow)(wf));
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
return legacyWorker;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Workflow as V0Workflow } from '../../../workflow';
|
|
2
1
|
import { BaseWorkflowDeclaration } from '../../declaration';
|
|
2
|
+
import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
|
|
3
3
|
import { SlotConfig } from '../../slot-types';
|
|
4
4
|
export interface WorkerSlotOptions {
|
|
5
5
|
/** (optional) Maximum number of concurrent runs on this worker, defaults to 100 */
|
|
6
6
|
slots?: number;
|
|
7
7
|
/** (optional) Maximum number of concurrent durable tasks, defaults to 1,000 */
|
|
8
8
|
durableSlots?: number;
|
|
9
|
-
/** (optional) Array of workflows to register */
|
|
10
|
-
workflows?: BaseWorkflowDeclaration<any, any>
|
|
9
|
+
/** (optional) Array of workflows to register (supports both v1 and legacy workflow formats) */
|
|
10
|
+
workflows?: Array<BaseWorkflowDeclaration<any, any> | LegacyWorkflow>;
|
|
11
11
|
/** @deprecated Use slots instead */
|
|
12
12
|
maxRuns?: number;
|
|
13
13
|
}
|