@lotiai/composer 0.2.0 → 0.2.1
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/dist/build-config/index.d.ts +52 -0
- package/dist/build-config/index.d.ts.map +1 -0
- package/dist/build-config/index.js +66 -0
- package/dist/build-config/index.js.map +1 -0
- package/dist/build-config/loader.d.ts +80 -0
- package/dist/build-config/loader.d.ts.map +1 -0
- package/dist/build-config/loader.js +238 -0
- package/dist/build-config/loader.js.map +1 -0
- package/dist/build-config/schema.d.ts +101 -0
- package/dist/build-config/schema.d.ts.map +1 -0
- package/dist/build-config/schema.js +94 -0
- package/dist/build-config/schema.js.map +1 -0
- package/dist/cli/commands/dev-temporal.d.ts +15 -0
- package/dist/cli/commands/dev-temporal.d.ts.map +1 -0
- package/dist/cli/commands/dev-temporal.js +68 -0
- package/dist/cli/commands/dev-temporal.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +21 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +421 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/profiles.d.ts +15 -0
- package/dist/cli/commands/profiles.d.ts.map +1 -0
- package/dist/cli/commands/profiles.js +69 -0
- package/dist/cli/commands/profiles.js.map +1 -0
- package/dist/cli/index.d.ts +21 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +44 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/async/build/workflow-factory.d.ts +212 -0
- package/dist/internal/async/build/workflow-factory.d.ts.map +1 -0
- package/dist/internal/async/build/workflow-factory.js +533 -0
- package/dist/internal/async/build/workflow-factory.js.map +1 -0
- package/dist/internal/async/build-scripts/utils/common.d.ts +28 -0
- package/dist/internal/async/build-scripts/utils/common.d.ts.map +1 -0
- package/dist/internal/async/build-scripts/utils/common.js +50 -0
- package/dist/internal/async/build-scripts/utils/common.js.map +1 -0
- package/dist/internal/async/build-scripts/utils/import-module.d.ts +19 -0
- package/dist/internal/async/build-scripts/utils/import-module.d.ts.map +1 -0
- package/dist/internal/async/build-scripts/utils/import-module.js +80 -0
- package/dist/internal/async/build-scripts/utils/import-module.js.map +1 -0
- package/dist/internal/async/build-scripts/utils/type-guards.d.ts +123 -0
- package/dist/internal/async/build-scripts/utils/type-guards.d.ts.map +1 -0
- package/dist/internal/async/build-scripts/utils/type-guards.js +145 -0
- package/dist/internal/async/build-scripts/utils/type-guards.js.map +1 -0
- package/dist/internal/async/config/cleanup-policy.d.ts +50 -0
- package/dist/internal/async/config/cleanup-policy.d.ts.map +1 -0
- package/dist/internal/async/config/cleanup-policy.js +20 -0
- package/dist/internal/async/config/cleanup-policy.js.map +1 -0
- package/dist/internal/async/config/worker-profiles.d.ts +172 -0
- package/dist/internal/async/config/worker-profiles.d.ts.map +1 -0
- package/dist/internal/async/config/worker-profiles.js +275 -0
- package/dist/internal/async/config/worker-profiles.js.map +1 -0
- package/dist/internal/async/execute/temporal-client.d.ts +182 -0
- package/dist/internal/async/execute/temporal-client.d.ts.map +1 -0
- package/dist/internal/async/execute/temporal-client.js +190 -0
- package/dist/internal/async/execute/temporal-client.js.map +1 -0
- package/dist/internal/async/execute/workflow-execution.d.ts +98 -0
- package/dist/internal/async/execute/workflow-execution.d.ts.map +1 -0
- package/dist/internal/async/execute/workflow-execution.js +191 -0
- package/dist/internal/async/execute/workflow-execution.js.map +1 -0
- package/dist/internal/async/metrics/task-queue-metrics.d.ts +74 -0
- package/dist/internal/async/metrics/task-queue-metrics.d.ts.map +1 -0
- package/dist/internal/async/metrics/task-queue-metrics.js +155 -0
- package/dist/internal/async/metrics/task-queue-metrics.js.map +1 -0
- package/dist/internal/async/register/activity-worker.d.ts +123 -0
- package/dist/internal/async/register/activity-worker.d.ts.map +1 -0
- package/dist/internal/async/register/activity-worker.js +355 -0
- package/dist/internal/async/register/activity-worker.js.map +1 -0
- package/dist/internal/async/register/generate-workflow-source.d.ts +43 -0
- package/dist/internal/async/register/generate-workflow-source.d.ts.map +1 -0
- package/dist/internal/async/register/generate-workflow-source.js +193 -0
- package/dist/internal/async/register/generate-workflow-source.js.map +1 -0
- package/dist/internal/async/register/workflow-worker.d.ts +125 -0
- package/dist/internal/async/register/workflow-worker.d.ts.map +1 -0
- package/dist/internal/async/register/workflow-worker.js +215 -0
- package/dist/internal/async/register/workflow-worker.js.map +1 -0
- package/dist/internal/async/register-scripts/start-activity-worker.d.ts +70 -0
- package/dist/internal/async/register-scripts/start-activity-worker.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/start-activity-worker.js +75 -0
- package/dist/internal/async/register-scripts/start-activity-worker.js.map +1 -0
- package/dist/internal/async/register-scripts/start-all-workers.d.ts +81 -0
- package/dist/internal/async/register-scripts/start-all-workers.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/start-all-workers.js +84 -0
- package/dist/internal/async/register-scripts/start-all-workers.js.map +1 -0
- package/dist/internal/async/register-scripts/start-workflow-worker.d.ts +69 -0
- package/dist/internal/async/register-scripts/start-workflow-worker.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/start-workflow-worker.js +74 -0
- package/dist/internal/async/register-scripts/start-workflow-worker.js.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules-cli.d.ts +28 -0
- package/dist/internal/async/register-scripts/sync-schedules-cli.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules-cli.js +124 -0
- package/dist/internal/async/register-scripts/sync-schedules-cli.js.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules-via-lambda.d.ts +55 -0
- package/dist/internal/async/register-scripts/sync-schedules-via-lambda.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules-via-lambda.js +146 -0
- package/dist/internal/async/register-scripts/sync-schedules-via-lambda.js.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules.d.ts +68 -0
- package/dist/internal/async/register-scripts/sync-schedules.d.ts.map +1 -0
- package/dist/internal/async/register-scripts/sync-schedules.js +83 -0
- package/dist/internal/async/register-scripts/sync-schedules.js.map +1 -0
- package/dist/internal/async/schedule/constants.d.ts +10 -0
- package/dist/internal/async/schedule/constants.d.ts.map +1 -0
- package/dist/internal/async/schedule/constants.js +13 -0
- package/dist/internal/async/schedule/constants.js.map +1 -0
- package/dist/internal/async/schedule/define-schedule.d.ts +192 -0
- package/dist/internal/async/schedule/define-schedule.d.ts.map +1 -0
- package/dist/internal/async/schedule/define-schedule.js +79 -0
- package/dist/internal/async/schedule/define-schedule.js.map +1 -0
- package/dist/internal/async/schedule/index.d.ts +3 -0
- package/dist/internal/async/schedule/index.d.ts.map +1 -0
- package/dist/internal/async/schedule/index.js +9 -0
- package/dist/internal/async/schedule/index.js.map +1 -0
- package/dist/internal/async/schedule/schedule-definition-schema.d.ts +64 -0
- package/dist/internal/async/schedule/schedule-definition-schema.d.ts.map +1 -0
- package/dist/internal/async/schedule/schedule-definition-schema.js +77 -0
- package/dist/internal/async/schedule/schedule-definition-schema.js.map +1 -0
- package/dist/internal/async/schedule/sync-schedules.d.ts +71 -0
- package/dist/internal/async/schedule/sync-schedules.d.ts.map +1 -0
- package/dist/internal/async/schedule/sync-schedules.js +231 -0
- package/dist/internal/async/schedule/sync-schedules.js.map +1 -0
- package/dist/internal/async/utils/ensure-namespace.d.ts +16 -0
- package/dist/internal/async/utils/ensure-namespace.d.ts.map +1 -0
- package/dist/internal/async/utils/ensure-namespace.js +64 -0
- package/dist/internal/async/utils/ensure-namespace.js.map +1 -0
- package/dist/internal/async/utils/find-package-root.d.ts +9 -0
- package/dist/internal/async/utils/find-package-root.d.ts.map +1 -0
- package/dist/internal/async/utils/find-package-root.js +28 -0
- package/dist/internal/async/utils/find-package-root.js.map +1 -0
- package/dist/internal/async/utils/is-composer-error.d.ts +14 -0
- package/dist/internal/async/utils/is-composer-error.d.ts.map +1 -0
- package/dist/internal/async/utils/is-composer-error.js +17 -0
- package/dist/internal/async/utils/is-composer-error.js.map +1 -0
- package/dist/internal/context-provider.d.ts +316 -0
- package/dist/internal/context-provider.d.ts.map +1 -0
- package/dist/internal/context-provider.js +12 -0
- package/dist/internal/context-provider.js.map +1 -0
- package/dist/internal/create-composer.d.ts +57 -0
- package/dist/internal/create-composer.d.ts.map +1 -0
- package/dist/internal/create-composer.js +125 -0
- package/dist/internal/create-composer.js.map +1 -0
- package/dist/internal/dag-sync-fanout.d.ts +79 -0
- package/dist/internal/dag-sync-fanout.d.ts.map +1 -0
- package/dist/internal/dag-sync-fanout.js +59 -0
- package/dist/internal/dag-sync-fanout.js.map +1 -0
- package/dist/internal/dag-sync-step.d.ts +230 -0
- package/dist/internal/dag-sync-step.d.ts.map +1 -0
- package/dist/internal/dag-sync-step.js +159 -0
- package/dist/internal/dag-sync-step.js.map +1 -0
- package/dist/internal/dag-sync-workflow.d.ts +535 -0
- package/dist/internal/dag-sync-workflow.d.ts.map +1 -0
- package/dist/internal/dag-sync-workflow.js +843 -0
- package/dist/internal/dag-sync-workflow.js.map +1 -0
- package/dist/internal/defaults.d.ts +24 -0
- package/dist/internal/defaults.d.ts.map +1 -0
- package/dist/internal/defaults.js +102 -0
- package/dist/internal/defaults.js.map +1 -0
- package/dist/internal/errors.d.ts +109 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +212 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/index.d.ts +9 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +22 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/observability.d.ts +63 -0
- package/dist/internal/observability.d.ts.map +1 -0
- package/dist/internal/observability.js +323 -0
- package/dist/internal/observability.js.map +1 -0
- package/dist/internal/types.d.ts +80 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +9 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/internal/workflow-planning.d.ts +107 -0
- package/dist/internal/workflow-planning.d.ts.map +1 -0
- package/dist/internal/workflow-planning.js +216 -0
- package/dist/internal/workflow-planning.js.map +1 -0
- package/dist/schedule-sync.d.ts +17 -0
- package/dist/schedule-sync.d.ts.map +1 -0
- package/dist/schedule-sync.js +22 -0
- package/dist/schedule-sync.js.map +1 -0
- package/dist/temporal-naming.d.ts +27 -0
- package/dist/temporal-naming.d.ts.map +1 -0
- package/dist/temporal-naming.js +33 -0
- package/dist/temporal-naming.js.map +1 -0
- package/package.json +16 -17
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temporal Workflow Worker
|
|
3
|
+
*
|
|
4
|
+
* Registers and executes workflow orchestration logic in a deterministic sandbox.
|
|
5
|
+
* Accepts workflow definitions declaratively, generates workflow plans, writes a
|
|
6
|
+
* temporary source file, and lets Temporal's internal Webpack bundle it for the
|
|
7
|
+
* V8 sandbox.
|
|
8
|
+
*
|
|
9
|
+
* ## Workflow Worker Responsibilities:
|
|
10
|
+
* - Connect to Temporal Server
|
|
11
|
+
* - Generate WorkflowPlan objects from provided workflow definitions
|
|
12
|
+
* - Write a temp CJS file exporting workflow functions via createWorkflowFunction
|
|
13
|
+
* - Pass the temp file to Temporal's Webpack via workflowsPath
|
|
14
|
+
* - Execute workflow coordination (batch sequencing, parallel execution)
|
|
15
|
+
* - Schedule activities to appropriate task queues
|
|
16
|
+
*
|
|
17
|
+
* ## What Workflows CANNOT Do:
|
|
18
|
+
* - Access Node.js APIs (fs, http, process, etc.)
|
|
19
|
+
* - Use non-deterministic functions (Date.now(), Math.random(), crypto.randomBytes())
|
|
20
|
+
* - Make external API calls or database queries
|
|
21
|
+
* - Import business logic (all business logic runs in activities)
|
|
22
|
+
*
|
|
23
|
+
* @module workflow-worker
|
|
24
|
+
*/
|
|
25
|
+
import { NativeConnection, Worker } from "@temporalio/worker";
|
|
26
|
+
import type { Workflow } from "../../dag-sync-workflow";
|
|
27
|
+
import type { ComposerLogger } from "../../types";
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for the Workflow Worker.
|
|
30
|
+
*/
|
|
31
|
+
export interface WorkflowWorkerConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Temporal Server address (e.g., "localhost:7233" for local dev)
|
|
34
|
+
* @default "localhost:7233"
|
|
35
|
+
*/
|
|
36
|
+
serverAddress?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Temporal namespace to connect to
|
|
39
|
+
* @default "default"
|
|
40
|
+
*/
|
|
41
|
+
namespace?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Task queue(s) to listen on for workflow tasks.
|
|
44
|
+
* All workflows are registered to the same queue(s).
|
|
45
|
+
* @default ["workflow-tasks"]
|
|
46
|
+
*/
|
|
47
|
+
taskQueues?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Workflow definitions to register.
|
|
50
|
+
* Plans are generated from these at startup.
|
|
51
|
+
*/
|
|
52
|
+
workflows: Workflow<any, any, any>[];
|
|
53
|
+
/**
|
|
54
|
+
* Maximum number of concurrent workflow executions
|
|
55
|
+
* @default 100
|
|
56
|
+
*/
|
|
57
|
+
maxConcurrentWorkflowTaskExecutions?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Deployment series name for Worker Versioning (e.g., "orders-service-workflows").
|
|
60
|
+
* Derived from the service name via getDeploymentSeriesNames().
|
|
61
|
+
*/
|
|
62
|
+
deploymentSeriesName: string;
|
|
63
|
+
/**
|
|
64
|
+
* Build identifier for Worker Versioning (typically git commit SHA).
|
|
65
|
+
* When set, workers register with this buildId for version-aware routing.
|
|
66
|
+
* When unset, Worker Versioning is disabled.
|
|
67
|
+
*/
|
|
68
|
+
buildId?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Logger for worker lifecycle messages.
|
|
71
|
+
* If not provided, defaults to the console-based defaultLogger.
|
|
72
|
+
*/
|
|
73
|
+
logger?: ComposerLogger;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates Temporal Workflow Workers with automatic connection management.
|
|
77
|
+
*
|
|
78
|
+
* At startup:
|
|
79
|
+
* 1. Generates WorkflowPlan objects from provided workflow definitions
|
|
80
|
+
* 2. Writes a temp CJS file with createWorkflowFunction calls
|
|
81
|
+
* 3. Passes the temp file to Temporal's Webpack via workflowsPath
|
|
82
|
+
* 4. Creates worker instances for the specified task queues
|
|
83
|
+
*
|
|
84
|
+
* @param config - Worker configuration
|
|
85
|
+
* @returns Object containing workers array and the created connection
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const { workers, connection } = await createWorkflowWorkers({
|
|
90
|
+
* workflows: [myWorkflow],
|
|
91
|
+
* taskQueues: ["workflow-tasks"],
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Run workers
|
|
95
|
+
* await Promise.all(workers.map(w => w.run()));
|
|
96
|
+
*
|
|
97
|
+
* // Cleanup
|
|
98
|
+
* await Promise.all(workers.map(w => w.shutdown()));
|
|
99
|
+
* await connection.close();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function createWorkflowWorkers(config: WorkflowWorkerConfig): Promise<{
|
|
103
|
+
workers: Worker[];
|
|
104
|
+
connection: NativeConnection;
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* Starts Workflow Workers and runs them until interrupted.
|
|
108
|
+
*
|
|
109
|
+
* Creates a Temporal connection, initializes workers from provided workflows, and
|
|
110
|
+
* handles graceful shutdown on SIGINT/SIGTERM. The connection is automatically
|
|
111
|
+
* managed and closed on shutdown.
|
|
112
|
+
*
|
|
113
|
+
* @param config - Worker configuration
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Run workflow workers (blocks until interrupted)
|
|
118
|
+
* await runWorkflowWorkers({
|
|
119
|
+
* workflows: [myWorkflow],
|
|
120
|
+
* taskQueues: ["workflow-tasks"],
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function runWorkflowWorkers(config: WorkflowWorkerConfig): Promise<void>;
|
|
125
|
+
//# sourceMappingURL=workflow-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-worker.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register/workflow-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqBlD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAErC;;;OAGG;IACH,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAE7C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAsF9D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCpF"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Temporal Workflow Worker
|
|
4
|
+
*
|
|
5
|
+
* Registers and executes workflow orchestration logic in a deterministic sandbox.
|
|
6
|
+
* Accepts workflow definitions declaratively, generates workflow plans, writes a
|
|
7
|
+
* temporary source file, and lets Temporal's internal Webpack bundle it for the
|
|
8
|
+
* V8 sandbox.
|
|
9
|
+
*
|
|
10
|
+
* ## Workflow Worker Responsibilities:
|
|
11
|
+
* - Connect to Temporal Server
|
|
12
|
+
* - Generate WorkflowPlan objects from provided workflow definitions
|
|
13
|
+
* - Write a temp CJS file exporting workflow functions via createWorkflowFunction
|
|
14
|
+
* - Pass the temp file to Temporal's Webpack via workflowsPath
|
|
15
|
+
* - Execute workflow coordination (batch sequencing, parallel execution)
|
|
16
|
+
* - Schedule activities to appropriate task queues
|
|
17
|
+
*
|
|
18
|
+
* ## What Workflows CANNOT Do:
|
|
19
|
+
* - Access Node.js APIs (fs, http, process, etc.)
|
|
20
|
+
* - Use non-deterministic functions (Date.now(), Math.random(), crypto.randomBytes())
|
|
21
|
+
* - Make external API calls or database queries
|
|
22
|
+
* - Import business logic (all business logic runs in activities)
|
|
23
|
+
*
|
|
24
|
+
* @module workflow-worker
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.createWorkflowWorkers = createWorkflowWorkers;
|
|
28
|
+
exports.runWorkflowWorkers = runWorkflowWorkers;
|
|
29
|
+
const node_path_1 = require("node:path");
|
|
30
|
+
const common_1 = require("@temporalio/common");
|
|
31
|
+
const worker_1 = require("@temporalio/worker");
|
|
32
|
+
const defaults_1 = require("../../defaults");
|
|
33
|
+
const generate_workflow_source_1 = require("./generate-workflow-source");
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the node_modules directory containing @temporalio/workflow.
|
|
36
|
+
*
|
|
37
|
+
* Temporal's workflow Worker uses webpack internally to bundle workflow code
|
|
38
|
+
* into a deterministic sandbox. Webpack needs to resolve `@temporalio/workflow`
|
|
39
|
+
* at bundle time, but pnpm's strict node_modules structure may not hoist it
|
|
40
|
+
* to the consumer's top-level node_modules. Since @lotiai/composer lists
|
|
41
|
+
* @temporalio/workflow as a direct dependency, require.resolve finds it from
|
|
42
|
+
* here. We pass this directory to webpack via bundlerOptions so it can resolve
|
|
43
|
+
* the package regardless of the consumer's package manager layout.
|
|
44
|
+
*/
|
|
45
|
+
function getTemporalWorkflowNodeModulesDir() {
|
|
46
|
+
const temporalWorkflowPkg = require.resolve("@temporalio/workflow/package.json");
|
|
47
|
+
// Go up from .../node_modules/@temporalio/workflow/package.json
|
|
48
|
+
// to .../node_modules (scoped package = 2 levels above the package dir)
|
|
49
|
+
return (0, node_path_1.resolve)((0, node_path_1.dirname)(temporalWorkflowPkg), "..", "..");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Default configuration for local development.
|
|
53
|
+
*/
|
|
54
|
+
const DEFAULT_CONFIG = {
|
|
55
|
+
serverAddress: "localhost:7233",
|
|
56
|
+
namespace: "default",
|
|
57
|
+
taskQueues: ["workflow-tasks"],
|
|
58
|
+
maxConcurrentWorkflowTaskExecutions: 100,
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Creates Temporal Workflow Workers with automatic connection management.
|
|
62
|
+
*
|
|
63
|
+
* At startup:
|
|
64
|
+
* 1. Generates WorkflowPlan objects from provided workflow definitions
|
|
65
|
+
* 2. Writes a temp CJS file with createWorkflowFunction calls
|
|
66
|
+
* 3. Passes the temp file to Temporal's Webpack via workflowsPath
|
|
67
|
+
* 4. Creates worker instances for the specified task queues
|
|
68
|
+
*
|
|
69
|
+
* @param config - Worker configuration
|
|
70
|
+
* @returns Object containing workers array and the created connection
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const { workers, connection } = await createWorkflowWorkers({
|
|
75
|
+
* workflows: [myWorkflow],
|
|
76
|
+
* taskQueues: ["workflow-tasks"],
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Run workers
|
|
80
|
+
* await Promise.all(workers.map(w => w.run()));
|
|
81
|
+
*
|
|
82
|
+
* // Cleanup
|
|
83
|
+
* await Promise.all(workers.map(w => w.shutdown()));
|
|
84
|
+
* await connection.close();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
async function createWorkflowWorkers(config) {
|
|
88
|
+
const logger = config.logger ?? defaults_1.defaultLogger;
|
|
89
|
+
const finalConfig = { ...DEFAULT_CONFIG, ...config };
|
|
90
|
+
const workflowCount = config.workflows.length;
|
|
91
|
+
logger.info("Creating Workflow Workers", {
|
|
92
|
+
server: finalConfig.serverAddress,
|
|
93
|
+
namespace: finalConfig.namespace,
|
|
94
|
+
taskQueues: finalConfig.taskQueues,
|
|
95
|
+
workflowCount,
|
|
96
|
+
});
|
|
97
|
+
const workflowsPath = await (0, generate_workflow_source_1.writeWorkflowSourceFile)(config.workflows);
|
|
98
|
+
logger.info("Workflow source file generated", { workflowsPath });
|
|
99
|
+
const connection = await worker_1.NativeConnection.connect({
|
|
100
|
+
address: finalConfig.serverAddress,
|
|
101
|
+
});
|
|
102
|
+
// TODO: This webpackConfigHook may no longer be necessary. It was added when
|
|
103
|
+
// the esbuild bundle lived in the consumer's dist/ and webpack resolved
|
|
104
|
+
// @temporalio/workflow from there (where it's not a direct dep). Now that
|
|
105
|
+
// workflow-factory.js is loaded via absolute path from @lotiai/composer (which
|
|
106
|
+
// has @temporalio/workflow as a direct dep), webpack should resolve it
|
|
107
|
+
// normally. Try removing the hook + getTemporalWorkflowNodeModulesDir and
|
|
108
|
+
// verify the workflow worker still starts.
|
|
109
|
+
const temporalNodeModulesDir = getTemporalWorkflowNodeModulesDir();
|
|
110
|
+
// Create workers for each task queue
|
|
111
|
+
// Note: Temporal requires one Worker per task queue, but they all load the same workflows
|
|
112
|
+
const workers = await Promise.all(finalConfig.taskQueues.map(async (taskQueue) => {
|
|
113
|
+
const worker = await worker_1.Worker.create({
|
|
114
|
+
connection,
|
|
115
|
+
namespace: finalConfig.namespace,
|
|
116
|
+
taskQueue,
|
|
117
|
+
workflowsPath,
|
|
118
|
+
maxConcurrentWorkflowTaskExecutions: finalConfig.maxConcurrentWorkflowTaskExecutions,
|
|
119
|
+
// Enable Build ID versioning for safe rainbow deploys when a git hash is available.
|
|
120
|
+
// PINNED ensures workflows started on a specific version continue using that version.
|
|
121
|
+
...(config.buildId
|
|
122
|
+
? {
|
|
123
|
+
workerDeploymentOptions: {
|
|
124
|
+
useWorkerVersioning: true,
|
|
125
|
+
version: {
|
|
126
|
+
deploymentName: config.deploymentSeriesName,
|
|
127
|
+
buildId: config.buildId,
|
|
128
|
+
},
|
|
129
|
+
defaultVersioningBehavior: common_1.VersioningBehavior.PINNED,
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
133
|
+
bundlerOptions: {
|
|
134
|
+
// Tell webpack where to find @temporalio/workflow. Without this, pnpm's
|
|
135
|
+
// strict node_modules layout prevents webpack from resolving it when the
|
|
136
|
+
// workflow source file lives in the consumer's dist/ directory.
|
|
137
|
+
webpackConfigHook: (config) => {
|
|
138
|
+
config.resolve = config.resolve ?? {};
|
|
139
|
+
const modules = config.resolve.modules ?? [];
|
|
140
|
+
if (!modules.includes(temporalNodeModulesDir)) {
|
|
141
|
+
modules.push(temporalNodeModulesDir);
|
|
142
|
+
}
|
|
143
|
+
config.resolve.modules = modules;
|
|
144
|
+
return config;
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
logger.info("Worker created for task queue", { taskQueue, namespace: finalConfig.namespace });
|
|
149
|
+
return worker;
|
|
150
|
+
}));
|
|
151
|
+
// Return all workers (caller must run them all)
|
|
152
|
+
if (workers.length === 0) {
|
|
153
|
+
throw new Error("No task queues configured - cannot create workers");
|
|
154
|
+
}
|
|
155
|
+
logger.info("Workflow Workers ready", {
|
|
156
|
+
taskQueues: finalConfig.taskQueues,
|
|
157
|
+
workerCount: workers.length,
|
|
158
|
+
workflowCount,
|
|
159
|
+
});
|
|
160
|
+
return { workers, connection };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Starts Workflow Workers and runs them until interrupted.
|
|
164
|
+
*
|
|
165
|
+
* Creates a Temporal connection, initializes workers from provided workflows, and
|
|
166
|
+
* handles graceful shutdown on SIGINT/SIGTERM. The connection is automatically
|
|
167
|
+
* managed and closed on shutdown.
|
|
168
|
+
*
|
|
169
|
+
* @param config - Worker configuration
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Run workflow workers (blocks until interrupted)
|
|
174
|
+
* await runWorkflowWorkers({
|
|
175
|
+
* workflows: [myWorkflow],
|
|
176
|
+
* taskQueues: ["workflow-tasks"],
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
async function runWorkflowWorkers(config) {
|
|
181
|
+
const logger = config.logger ?? defaults_1.defaultLogger;
|
|
182
|
+
const { workers, connection } = await createWorkflowWorkers(config);
|
|
183
|
+
// Setup graceful shutdown for all workers
|
|
184
|
+
let isShuttingDown = false;
|
|
185
|
+
const shutdown = async () => {
|
|
186
|
+
if (isShuttingDown)
|
|
187
|
+
return; // Prevent duplicate shutdown
|
|
188
|
+
isShuttingDown = true;
|
|
189
|
+
logger.info("Shutting down Workflow Workers", { workerCount: workers.length });
|
|
190
|
+
await Promise.all(workers.map((worker) => worker.shutdown()));
|
|
191
|
+
await connection.close();
|
|
192
|
+
logger.info("Workflow Workers shutdown complete");
|
|
193
|
+
// TODO: process.exit(0) here makes this function non-composable when multiple
|
|
194
|
+
// worker types run in the same process (e.g., startAllWorkers). Consider
|
|
195
|
+
// returning cleanly and letting the caller control process exit. Look for:
|
|
196
|
+
// the Promise.all in startAllWorkers resolving naturally after shutdown,
|
|
197
|
+
// rather than racing on process.exit(0). Not urgent since production
|
|
198
|
+
// always uses separate containers and local dev handles this via Temporal
|
|
199
|
+
// server-side task retries.
|
|
200
|
+
process.exit(0);
|
|
201
|
+
};
|
|
202
|
+
process.on("SIGINT", () => void shutdown());
|
|
203
|
+
process.on("SIGTERM", () => void shutdown());
|
|
204
|
+
// Run all workers in parallel
|
|
205
|
+
try {
|
|
206
|
+
await Promise.all(workers.map((worker) => worker.run()));
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
logger.error("Workflow Workers error", {
|
|
210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
211
|
+
});
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=workflow-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-worker.js","sourceRoot":"","sources":["../../../../src/internal/async/register/workflow-worker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAwHH,sDAwFC;AAoBD,gDAqCC;AAvQD,yCAA6C;AAC7C,+CAAwD;AACxD,+CAA8D;AAE9D,6CAA+C;AAE/C,yEAAqE;AAErE;;;;;;;;;;GAUG;AACH,SAAS,iCAAiC;IACxC,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;IACjF,gEAAgE;IAChE,wEAAwE;IACxE,OAAO,IAAA,mBAAO,EAAC,IAAA,mBAAO,EAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAyDD;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,aAAa,EAAE,gBAAgB;IAC/B,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,CAAC,gBAAgB,CAAC;IAC9B,mCAAmC,EAAE,GAAG;CAChC,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACI,KAAK,UAAU,qBAAqB,CACzC,MAA4B;IAE5B,MAAM,M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O,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE;YACrC,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start Activity Worker
|
|
3
|
+
*
|
|
4
|
+
* Generic framework function that starts Temporal Activity Workers from a
|
|
5
|
+
* configured Composer instance. The Composer provides the Temporal connection
|
|
6
|
+
* config (server address, namespace), context provider, and logger.
|
|
7
|
+
*
|
|
8
|
+
* The caller is responsible for determining task queues and concurrency settings
|
|
9
|
+
* (e.g., from environment variables, worker profiles, or hardcoded defaults).
|
|
10
|
+
*
|
|
11
|
+
* ## Usage:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { startActivityWorker } from "@lotiai/composer";
|
|
15
|
+
* import { composer } from "./my-app-composer";
|
|
16
|
+
*
|
|
17
|
+
* await startActivityWorker(composer, {
|
|
18
|
+
* taskQueues: ["standard-tasks"],
|
|
19
|
+
* maxConcurrentActivityTaskExecutions: 15,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @module start-activity-worker
|
|
24
|
+
*/
|
|
25
|
+
import type { Composer } from "../../context-provider";
|
|
26
|
+
import type { Workflow } from "../../dag-sync-workflow";
|
|
27
|
+
/**
|
|
28
|
+
* Options for starting an activity worker.
|
|
29
|
+
*/
|
|
30
|
+
export interface StartActivityWorkerOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Task queues to listen on for activity tasks.
|
|
33
|
+
*/
|
|
34
|
+
taskQueues: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Maximum number of concurrent activity executions per queue.
|
|
37
|
+
*/
|
|
38
|
+
maxConcurrentActivityTaskExecutions: number;
|
|
39
|
+
/**
|
|
40
|
+
* Workflow definitions to register. Steps are extracted from these.
|
|
41
|
+
*/
|
|
42
|
+
workflows: Workflow<any, any, any>[];
|
|
43
|
+
/**
|
|
44
|
+
* Whether to ensure the Temporal namespace exists before starting workers.
|
|
45
|
+
* Useful for local development where the namespace may not exist yet.
|
|
46
|
+
*
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
ensureNamespace?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Starts Temporal Activity Workers using a configured Composer instance.
|
|
53
|
+
*
|
|
54
|
+
* This function:
|
|
55
|
+
* 1. Optionally ensures the Temporal namespace exists (idempotent)
|
|
56
|
+
* 2. Logs the worker configuration
|
|
57
|
+
* 3. Delegates to `composer.runActivityWorkers()` which handles worker lifecycle
|
|
58
|
+
* (connection, bundle loading, shutdown signals)
|
|
59
|
+
* 4. Exits with code 1 on failure
|
|
60
|
+
*
|
|
61
|
+
* The Composer instance provides:
|
|
62
|
+
* - Temporal server address and namespace (from its temporal config)
|
|
63
|
+
* - Context provider (for step execution lifecycle)
|
|
64
|
+
* - Logger (for structured log output)
|
|
65
|
+
*
|
|
66
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
67
|
+
* @param options - Worker startup options (task queues, concurrency)
|
|
68
|
+
*/
|
|
69
|
+
export declare function startActivityWorker<TContext>(composer: Composer<TContext>, options: StartActivityWorkerOptions): Promise<void>;
|
|
70
|
+
//# sourceMappingURL=start-activity-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-activity-worker.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-activity-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGxD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB;;OAEG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAE5C;;OAEG;IACH,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAErC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAChD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Start Activity Worker
|
|
4
|
+
*
|
|
5
|
+
* Generic framework function that starts Temporal Activity Workers from a
|
|
6
|
+
* configured Composer instance. The Composer provides the Temporal connection
|
|
7
|
+
* config (server address, namespace), context provider, and logger.
|
|
8
|
+
*
|
|
9
|
+
* The caller is responsible for determining task queues and concurrency settings
|
|
10
|
+
* (e.g., from environment variables, worker profiles, or hardcoded defaults).
|
|
11
|
+
*
|
|
12
|
+
* ## Usage:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { startActivityWorker } from "@lotiai/composer";
|
|
16
|
+
* import { composer } from "./my-app-composer";
|
|
17
|
+
*
|
|
18
|
+
* await startActivityWorker(composer, {
|
|
19
|
+
* taskQueues: ["standard-tasks"],
|
|
20
|
+
* maxConcurrentActivityTaskExecutions: 15,
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module start-activity-worker
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.startActivityWorker = startActivityWorker;
|
|
28
|
+
const ensure_namespace_1 = require("../utils/ensure-namespace");
|
|
29
|
+
/**
|
|
30
|
+
* Starts Temporal Activity Workers using a configured Composer instance.
|
|
31
|
+
*
|
|
32
|
+
* This function:
|
|
33
|
+
* 1. Optionally ensures the Temporal namespace exists (idempotent)
|
|
34
|
+
* 2. Logs the worker configuration
|
|
35
|
+
* 3. Delegates to `composer.runActivityWorkers()` which handles worker lifecycle
|
|
36
|
+
* (connection, bundle loading, shutdown signals)
|
|
37
|
+
* 4. Exits with code 1 on failure
|
|
38
|
+
*
|
|
39
|
+
* The Composer instance provides:
|
|
40
|
+
* - Temporal server address and namespace (from its temporal config)
|
|
41
|
+
* - Context provider (for step execution lifecycle)
|
|
42
|
+
* - Logger (for structured log output)
|
|
43
|
+
*
|
|
44
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
45
|
+
* @param options - Worker startup options (task queues, concurrency)
|
|
46
|
+
*/
|
|
47
|
+
async function startActivityWorker(composer, options) {
|
|
48
|
+
const logger = composer.logger;
|
|
49
|
+
const { serverAddress, namespace } = composer.temporal;
|
|
50
|
+
logger.info("Starting Activity Workers", {
|
|
51
|
+
serverAddress,
|
|
52
|
+
namespace,
|
|
53
|
+
taskQueues: options.taskQueues,
|
|
54
|
+
maxConcurrentActivityTaskExecutions: options.maxConcurrentActivityTaskExecutions,
|
|
55
|
+
ensureNamespace: options.ensureNamespace ?? true,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
// Ensure namespace exists before starting workers (idempotent)
|
|
59
|
+
if (options.ensureNamespace !== false) {
|
|
60
|
+
await (0, ensure_namespace_1.ensureNamespaceExists)(serverAddress, namespace);
|
|
61
|
+
}
|
|
62
|
+
await composer.runActivityWorkers({
|
|
63
|
+
taskQueues: options.taskQueues,
|
|
64
|
+
maxConcurrentActivityTaskExecutions: options.maxConcurrentActivityTaskExecutions,
|
|
65
|
+
workflows: options.workflows,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger.error("Failed to start Activity Workers", {
|
|
70
|
+
error: error instanceof Error ? error.message : String(error),
|
|
71
|
+
});
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=start-activity-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-activity-worker.js","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-activity-worker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAoDH,kDAgCC;AAhFD,gEAAkE;AA8BlE;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,mBAAmB,CACvC,QAA4B,EAC5B,OAAmC;IAEnC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC;IAEvD,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;QACvC,aAAa;QACb,SAAS;QACT,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,mCAAmC,EAAE,OAAO,CAAC,mCAAmC;QAChF,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;KACjD,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,+DAA+D;QAC/D,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;YACtC,MAAM,IAAA,wCAAqB,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,QAAQ,CAAC,kBAAkB,CAAC;YAChC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,mCAAmC,EAAE,OAAO,CAAC,mCAAmC;YAChF,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE;YAC/C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start All Workers
|
|
3
|
+
*
|
|
4
|
+
* Generic framework function that starts both Temporal Workflow Workers and
|
|
5
|
+
* Activity Workers in parallel from a configured Composer instance. This is a
|
|
6
|
+
* convenience function for local development when you want to run the entire
|
|
7
|
+
* worker system in a single process.
|
|
8
|
+
*
|
|
9
|
+
* ## Usage:
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { startAllWorkers } from "@lotiai/composer";
|
|
13
|
+
* import { composer } from "./my-app-composer";
|
|
14
|
+
* import { myWorkflow } from "./workflows/my-workflow";
|
|
15
|
+
*
|
|
16
|
+
* await startAllWorkers(composer, {
|
|
17
|
+
* workflows: [myWorkflow],
|
|
18
|
+
* workflow: {
|
|
19
|
+
* taskQueues: ["workflow-tasks"],
|
|
20
|
+
* maxConcurrentWorkflowTaskExecutions: 100,
|
|
21
|
+
* },
|
|
22
|
+
* activity: {
|
|
23
|
+
* taskQueues: ["standard-tasks"],
|
|
24
|
+
* maxConcurrentActivityTaskExecutions: 15,
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Note:
|
|
30
|
+
*
|
|
31
|
+
* In production, you would typically run these workers in separate containers/processes
|
|
32
|
+
* to enable independent scaling and deployment. This function is primarily for
|
|
33
|
+
* local development convenience.
|
|
34
|
+
*
|
|
35
|
+
* @module start-all-workers
|
|
36
|
+
*/
|
|
37
|
+
import type { Composer } from "../../context-provider";
|
|
38
|
+
import type { Workflow } from "../../dag-sync-workflow";
|
|
39
|
+
import { type StartActivityWorkerOptions } from "./start-activity-worker";
|
|
40
|
+
import { type StartWorkflowWorkerOptions } from "./start-workflow-worker";
|
|
41
|
+
/**
|
|
42
|
+
* Options for starting all workers (workflow + activity) in a single process.
|
|
43
|
+
*/
|
|
44
|
+
export interface StartAllWorkersOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Workflow definitions shared by both workers.
|
|
47
|
+
* Activity worker extracts steps; workflow worker generates plans.
|
|
48
|
+
*/
|
|
49
|
+
workflows: Workflow<any, any, any>[];
|
|
50
|
+
/**
|
|
51
|
+
* Options for the workflow worker (task queues, concurrency).
|
|
52
|
+
* The `ensureNamespace` and `workflows` options are controlled at the top level.
|
|
53
|
+
*/
|
|
54
|
+
workflow: Omit<StartWorkflowWorkerOptions, "ensureNamespace" | "workflows">;
|
|
55
|
+
/**
|
|
56
|
+
* Options for the activity worker (task queues, concurrency).
|
|
57
|
+
* The `ensureNamespace` and `workflows` options are controlled at the top level.
|
|
58
|
+
*/
|
|
59
|
+
activity: Omit<StartActivityWorkerOptions, "ensureNamespace" | "workflows">;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to ensure the Temporal namespace exists before starting workers.
|
|
62
|
+
* When true, the namespace check is performed once before starting both workers.
|
|
63
|
+
*
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
ensureNamespace?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Starts both Temporal Workflow Workers and Activity Workers in parallel
|
|
70
|
+
* using a configured Composer instance.
|
|
71
|
+
*
|
|
72
|
+
* This function:
|
|
73
|
+
* 1. Optionally ensures the Temporal namespace exists (once, not per worker)
|
|
74
|
+
* 2. Logs the combined worker configuration
|
|
75
|
+
* 3. Delegates to `startWorkflowWorker()` and `startActivityWorker()` via `Promise.all`
|
|
76
|
+
*
|
|
77
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
78
|
+
* @param options - Combined worker startup options
|
|
79
|
+
*/
|
|
80
|
+
export declare function startAllWorkers<TContext>(composer: Composer<TContext>, options: StartAllWorkersOptions): Promise<void>;
|
|
81
|
+
//# sourceMappingURL=start-all-workers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-all-workers.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-all-workers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,KAAK,0BAA0B,EAAuB,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,KAAK,0BAA0B,EAAuB,MAAM,yBAAyB,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAErC;;;OAGG;IACH,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,iBAAiB,GAAG,WAAW,CAAC,CAAC;IAE5E;;;OAGG;IACH,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,iBAAiB,GAAG,WAAW,CAAC,CAAC;IAE5E;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAC5C,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|