@lotiai/composer 0.2.0 → 0.2.2
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 +29 -17
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Start All Workers
|
|
4
|
+
*
|
|
5
|
+
* Generic framework function that starts both Temporal Workflow Workers and
|
|
6
|
+
* Activity Workers in parallel from a configured Composer instance. This is a
|
|
7
|
+
* convenience function for local development when you want to run the entire
|
|
8
|
+
* worker system in a single process.
|
|
9
|
+
*
|
|
10
|
+
* ## Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { startAllWorkers } from "@lotiai/composer";
|
|
14
|
+
* import { composer } from "./my-app-composer";
|
|
15
|
+
* import { myWorkflow } from "./workflows/my-workflow";
|
|
16
|
+
*
|
|
17
|
+
* await startAllWorkers(composer, {
|
|
18
|
+
* workflows: [myWorkflow],
|
|
19
|
+
* workflow: {
|
|
20
|
+
* taskQueues: ["workflow-tasks"],
|
|
21
|
+
* maxConcurrentWorkflowTaskExecutions: 100,
|
|
22
|
+
* },
|
|
23
|
+
* activity: {
|
|
24
|
+
* taskQueues: ["standard-tasks"],
|
|
25
|
+
* maxConcurrentActivityTaskExecutions: 15,
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ## Note:
|
|
31
|
+
*
|
|
32
|
+
* In production, you would typically run these workers in separate containers/processes
|
|
33
|
+
* to enable independent scaling and deployment. This function is primarily for
|
|
34
|
+
* local development convenience.
|
|
35
|
+
*
|
|
36
|
+
* @module start-all-workers
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.startAllWorkers = startAllWorkers;
|
|
40
|
+
const ensure_namespace_1 = require("../utils/ensure-namespace");
|
|
41
|
+
const start_activity_worker_1 = require("./start-activity-worker");
|
|
42
|
+
const start_workflow_worker_1 = require("./start-workflow-worker");
|
|
43
|
+
/**
|
|
44
|
+
* Starts both Temporal Workflow Workers and Activity Workers in parallel
|
|
45
|
+
* using a configured Composer instance.
|
|
46
|
+
*
|
|
47
|
+
* This function:
|
|
48
|
+
* 1. Optionally ensures the Temporal namespace exists (once, not per worker)
|
|
49
|
+
* 2. Logs the combined worker configuration
|
|
50
|
+
* 3. Delegates to `startWorkflowWorker()` and `startActivityWorker()` via `Promise.all`
|
|
51
|
+
*
|
|
52
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
53
|
+
* @param options - Combined worker startup options
|
|
54
|
+
*/
|
|
55
|
+
async function startAllWorkers(composer, options) {
|
|
56
|
+
const logger = composer.logger;
|
|
57
|
+
const { serverAddress, namespace } = composer.temporal;
|
|
58
|
+
logger.info("Starting All Workers", {
|
|
59
|
+
serverAddress,
|
|
60
|
+
namespace,
|
|
61
|
+
workflowTaskQueues: options.workflow.taskQueues,
|
|
62
|
+
activityTaskQueues: options.activity.taskQueues,
|
|
63
|
+
maxConcurrentWorkflowTaskExecutions: options.workflow.maxConcurrentWorkflowTaskExecutions,
|
|
64
|
+
maxConcurrentActivityTaskExecutions: options.activity.maxConcurrentActivityTaskExecutions,
|
|
65
|
+
ensureNamespace: options.ensureNamespace ?? true,
|
|
66
|
+
});
|
|
67
|
+
// Ensure namespace once before starting both workers
|
|
68
|
+
if (options.ensureNamespace !== false) {
|
|
69
|
+
await (0, ensure_namespace_1.ensureNamespaceExists)(serverAddress, namespace);
|
|
70
|
+
}
|
|
71
|
+
await Promise.all([
|
|
72
|
+
(0, start_workflow_worker_1.startWorkflowWorker)(composer, {
|
|
73
|
+
...options.workflow,
|
|
74
|
+
workflows: options.workflows,
|
|
75
|
+
ensureNamespace: false,
|
|
76
|
+
}),
|
|
77
|
+
(0, start_activity_worker_1.startActivityWorker)(composer, {
|
|
78
|
+
...options.activity,
|
|
79
|
+
workflows: options.workflows,
|
|
80
|
+
ensureNamespace: false,
|
|
81
|
+
}),
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=start-all-workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-all-workers.js","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-all-workers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;;AAmDH,0CAkCC;AAjFD,gEAAkE;AAClE,mEAA+F;AAC/F,mEAA+F;AAiC/F;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,eAAe,CACnC,QAA4B,EAC5B,OAA+B;IAE/B,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,sBAAsB,EAAE;QAClC,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU;QAC/C,kBAAkB,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU;QAC/C,mCAAmC,EAAE,OAAO,CAAC,QAAQ,CAAC,mCAAmC;QACzF,mCAAmC,EAAE,OAAO,CAAC,QAAQ,CAAC,mCAAmC;QACzF,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;KACjD,CAAC,CAAC;IAEH,qDAAqD;IACrD,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACtC,MAAM,IAAA,wCAAqB,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,IAAA,2CAAmB,EAAC,QAAQ,EAAE;YAC5B,GAAG,OAAO,CAAC,QAAQ;YACnB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,eAAe,EAAE,KAAK;SACvB,CAAC;QACF,IAAA,2CAAmB,EAAC,QAAQ,EAAE;YAC5B,GAAG,OAAO,CAAC,QAAQ;YACnB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,eAAe,EAAE,KAAK;SACvB,CAAC;KACH,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start Workflow Worker
|
|
3
|
+
*
|
|
4
|
+
* Generic framework function that starts Temporal Workflow Workers from a
|
|
5
|
+
* configured Composer instance. The Composer provides the Temporal connection
|
|
6
|
+
* config (server address, namespace) and logger.
|
|
7
|
+
*
|
|
8
|
+
* The caller is responsible for determining task queues and concurrency settings
|
|
9
|
+
* (e.g., from environment variables or hardcoded defaults).
|
|
10
|
+
*
|
|
11
|
+
* ## Usage:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { startWorkflowWorker } from "@lotiai/composer";
|
|
15
|
+
* import { composer } from "./my-app-composer";
|
|
16
|
+
*
|
|
17
|
+
* await startWorkflowWorker(composer, {
|
|
18
|
+
* taskQueues: ["workflow-tasks"],
|
|
19
|
+
* maxConcurrentWorkflowTaskExecutions: 100,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @module start-workflow-worker
|
|
24
|
+
*/
|
|
25
|
+
import type { Composer } from "../../context-provider";
|
|
26
|
+
import type { Workflow } from "../../dag-sync-workflow";
|
|
27
|
+
/**
|
|
28
|
+
* Options for starting a workflow worker.
|
|
29
|
+
*/
|
|
30
|
+
export interface StartWorkflowWorkerOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Task queues to listen on for workflow tasks.
|
|
33
|
+
*/
|
|
34
|
+
taskQueues: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Maximum number of concurrent workflow task executions per queue.
|
|
37
|
+
*/
|
|
38
|
+
maxConcurrentWorkflowTaskExecutions: number;
|
|
39
|
+
/**
|
|
40
|
+
* Workflow definitions to register. Plans are generated 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 Workflow 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.runWorkflowWorkers()` 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
|
+
* - Logger (for structured log output)
|
|
64
|
+
*
|
|
65
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
66
|
+
* @param options - Worker startup options (task queues, concurrency)
|
|
67
|
+
*/
|
|
68
|
+
export declare function startWorkflowWorker<TContext>(composer: Composer<TContext>, options: StartWorkflowWorkerOptions): Promise<void>;
|
|
69
|
+
//# sourceMappingURL=start-workflow-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-workflow-worker.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-workflow-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;;;;;;;;;;;;;;;;GAgBG;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,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Start Workflow Worker
|
|
4
|
+
*
|
|
5
|
+
* Generic framework function that starts Temporal Workflow Workers from a
|
|
6
|
+
* configured Composer instance. The Composer provides the Temporal connection
|
|
7
|
+
* config (server address, namespace) and logger.
|
|
8
|
+
*
|
|
9
|
+
* The caller is responsible for determining task queues and concurrency settings
|
|
10
|
+
* (e.g., from environment variables or hardcoded defaults).
|
|
11
|
+
*
|
|
12
|
+
* ## Usage:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { startWorkflowWorker } from "@lotiai/composer";
|
|
16
|
+
* import { composer } from "./my-app-composer";
|
|
17
|
+
*
|
|
18
|
+
* await startWorkflowWorker(composer, {
|
|
19
|
+
* taskQueues: ["workflow-tasks"],
|
|
20
|
+
* maxConcurrentWorkflowTaskExecutions: 100,
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module start-workflow-worker
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.startWorkflowWorker = startWorkflowWorker;
|
|
28
|
+
const ensure_namespace_1 = require("../utils/ensure-namespace");
|
|
29
|
+
/**
|
|
30
|
+
* Starts Temporal Workflow 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.runWorkflowWorkers()` 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
|
+
* - Logger (for structured log output)
|
|
42
|
+
*
|
|
43
|
+
* @param composer - A fully configured Composer instance (must have temporal config)
|
|
44
|
+
* @param options - Worker startup options (task queues, concurrency)
|
|
45
|
+
*/
|
|
46
|
+
async function startWorkflowWorker(composer, options) {
|
|
47
|
+
const logger = composer.logger;
|
|
48
|
+
const { serverAddress, namespace } = composer.temporal;
|
|
49
|
+
logger.info("Starting Workflow Workers", {
|
|
50
|
+
serverAddress,
|
|
51
|
+
namespace,
|
|
52
|
+
taskQueues: options.taskQueues,
|
|
53
|
+
maxConcurrentWorkflowTaskExecutions: options.maxConcurrentWorkflowTaskExecutions,
|
|
54
|
+
ensureNamespace: options.ensureNamespace ?? true,
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
// Ensure namespace exists before starting workers (idempotent)
|
|
58
|
+
if (options.ensureNamespace !== false) {
|
|
59
|
+
await (0, ensure_namespace_1.ensureNamespaceExists)(serverAddress, namespace);
|
|
60
|
+
}
|
|
61
|
+
await composer.runWorkflowWorkers({
|
|
62
|
+
taskQueues: options.taskQueues,
|
|
63
|
+
maxConcurrentWorkflowTaskExecutions: options.maxConcurrentWorkflowTaskExecutions,
|
|
64
|
+
workflows: options.workflows,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger.error("Failed to start Workflow Workers", {
|
|
69
|
+
error: error instanceof Error ? error.message : String(error),
|
|
70
|
+
});
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=start-workflow-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-workflow-worker.js","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/start-workflow-worker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAmDH,kDAgCC;AA/ED,gEAAkE;AA8BlE;;;;;;;;;;;;;;;;GAgBG;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,28 @@
|
|
|
1
|
+
import type { Composer } from "../../context-provider";
|
|
2
|
+
import type { ScheduleDefinition } from "../schedule/define-schedule";
|
|
3
|
+
/**
|
|
4
|
+
* Options for `runSyncSchedulesCli`.
|
|
5
|
+
*/
|
|
6
|
+
export interface RunSyncSchedulesCliOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Schedule definitions to reconcile. Typically the values of a
|
|
9
|
+
* composer-instance's `schedules/` barrel filtered by
|
|
10
|
+
* `isScheduleDefinition`.
|
|
11
|
+
*/
|
|
12
|
+
schedules: ScheduleDefinition[];
|
|
13
|
+
/**
|
|
14
|
+
* argv to parse. Defaults to `process.argv`; primarily useful for
|
|
15
|
+
* testing.
|
|
16
|
+
*/
|
|
17
|
+
argv?: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parses CLI flags and dispatches to either `syncSchedulesViaLambda`
|
|
21
|
+
* (default) or `runScheduleSync` (with `--direct`). Intended to be the
|
|
22
|
+
* entire body of a composer-instance's `sync-schedules` script.
|
|
23
|
+
*
|
|
24
|
+
* @param composer - Composer instance providing the Temporal connection + logger
|
|
25
|
+
* @param options - Schedules to reconcile (and optional argv override)
|
|
26
|
+
*/
|
|
27
|
+
export declare function runSyncSchedulesCli<TContext>(composer: Composer<TContext>, options: RunSyncSchedulesCliOptions): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=sync-schedules-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-schedules-cli.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/sync-schedules-cli.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AActE;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAEhC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAChD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAiEf"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runSyncSchedulesCli = runSyncSchedulesCli;
|
|
7
|
+
/**
|
|
8
|
+
* Run Sync Schedules CLI
|
|
9
|
+
*
|
|
10
|
+
* Framework helper that implements the complete command-line entrypoint for
|
|
11
|
+
* a composer-instance's `sync-schedules` script. Each composer instance
|
|
12
|
+
* (interchange, josu, etc.) needs exactly one thin wrapper that:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { isScheduleDefinition, runSyncSchedulesCli } from "@lotiai/composer";
|
|
16
|
+
* import { getComposer } from "../app-composer";
|
|
17
|
+
* import * as scheduleExports from "../schedules";
|
|
18
|
+
*
|
|
19
|
+
* void runSyncSchedulesCli(getComposer(), {
|
|
20
|
+
* schedules: Object.values(scheduleExports).filter(isScheduleDefinition),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Everything else -- argv parsing, current-environment resolution, default
|
|
25
|
+
* Lambda function name, direct-vs-Lambda dispatch, and process exit on
|
|
26
|
+
* errors -- is owned here so flag names and behavior stay consistent across
|
|
27
|
+
* composer instances.
|
|
28
|
+
*
|
|
29
|
+
* ## Flags
|
|
30
|
+
*
|
|
31
|
+
* - `--lambda <name>` Override the schedule-sync Lambda function name.
|
|
32
|
+
* Defaults to `loti-ic-<ENVIRONMENT_NAME>-temporalschedulesync`.
|
|
33
|
+
* - `--mode invoke|emit` How to reconcile via the Lambda path. `invoke`
|
|
34
|
+
* (default) calls the Lambda; `emit` prints the JSON
|
|
35
|
+
* payload to stdout and exits 0.
|
|
36
|
+
* - `--dry-run` Reconcile in dry-run mode on the server
|
|
37
|
+
* (no changes). Defaults to
|
|
38
|
+
* `COMPOSER_SCHEDULE_SYNC_DRY_RUN === "true"`.
|
|
39
|
+
* - `--direct` Connect to Temporal directly from this process
|
|
40
|
+
* using the composer's configured `serverAddress`
|
|
41
|
+
* (local dev / escape hatch). Incompatible with
|
|
42
|
+
* `--mode`.
|
|
43
|
+
* - `--region <region>` AWS region for the Lambda client (default
|
|
44
|
+
* `us-east-1`).
|
|
45
|
+
*
|
|
46
|
+
* @module sync-schedules-cli
|
|
47
|
+
*/
|
|
48
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
49
|
+
const helpers_1 = require("yargs/helpers");
|
|
50
|
+
const sync_schedules_1 = require("./sync-schedules");
|
|
51
|
+
const sync_schedules_via_lambda_1 = require("./sync-schedules-via-lambda");
|
|
52
|
+
/**
|
|
53
|
+
* Builds the default schedule-sync Lambda function name for the current
|
|
54
|
+
* environment. Mirrors `createResourceName(taggingConfig,
|
|
55
|
+
* "temporal-schedule-sync")` in `infrastructure/shared`: `loti-ic` prefix +
|
|
56
|
+
* environment + resource slug with hyphens stripped.
|
|
57
|
+
*/
|
|
58
|
+
function defaultLambdaFunctionName(environment) {
|
|
59
|
+
return `loti-ic-${environment}-temporalschedulesync`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parses CLI flags and dispatches to either `syncSchedulesViaLambda`
|
|
63
|
+
* (default) or `runScheduleSync` (with `--direct`). Intended to be the
|
|
64
|
+
* entire body of a composer-instance's `sync-schedules` script.
|
|
65
|
+
*
|
|
66
|
+
* @param composer - Composer instance providing the Temporal connection + logger
|
|
67
|
+
* @param options - Schedules to reconcile (and optional argv override)
|
|
68
|
+
*/
|
|
69
|
+
async function runSyncSchedulesCli(composer, options) {
|
|
70
|
+
const argv = await (0, yargs_1.default)(options.argv ?? (0, helpers_1.hideBin)(process.argv))
|
|
71
|
+
.scriptName("sync-schedules")
|
|
72
|
+
.usage("$0 [--mode invoke|emit] [--dry-run] [--direct]")
|
|
73
|
+
.option("lambda", {
|
|
74
|
+
type: "string",
|
|
75
|
+
describe: "Name of the schedule-sync Lambda function (defaults to loti-ic-<env>-temporalschedulesync).",
|
|
76
|
+
})
|
|
77
|
+
.option("mode", {
|
|
78
|
+
type: "string",
|
|
79
|
+
choices: ["invoke", "emit"],
|
|
80
|
+
default: "invoke",
|
|
81
|
+
describe: 'How to reconcile: "invoke" calls the Lambda, "emit" prints the JSON payload to stdout and exits.',
|
|
82
|
+
})
|
|
83
|
+
.option("dry-run", {
|
|
84
|
+
type: "boolean",
|
|
85
|
+
describe: "Reconcile in dry-run mode (log the diff, change nothing). Defaults to the COMPOSER_SCHEDULE_SYNC_DRY_RUN env var.",
|
|
86
|
+
})
|
|
87
|
+
.option("direct", {
|
|
88
|
+
type: "boolean",
|
|
89
|
+
default: false,
|
|
90
|
+
describe: "Connect to Temporal directly from this process instead of invoking the Lambda (local dev).",
|
|
91
|
+
})
|
|
92
|
+
.option("region", {
|
|
93
|
+
type: "string",
|
|
94
|
+
describe: "AWS region for the Lambda client (defaults to us-east-1).",
|
|
95
|
+
})
|
|
96
|
+
.strict()
|
|
97
|
+
.help()
|
|
98
|
+
.parseAsync();
|
|
99
|
+
const currentEnvironment = process.env.ENVIRONMENT_NAME ?? null;
|
|
100
|
+
if (argv.direct) {
|
|
101
|
+
if (argv.mode !== "invoke") {
|
|
102
|
+
throw new Error("--mode is only valid when invoking the Lambda; remove --direct or --mode");
|
|
103
|
+
}
|
|
104
|
+
await (0, sync_schedules_1.runScheduleSync)(composer, {
|
|
105
|
+
schedules: options.schedules,
|
|
106
|
+
currentEnvironment,
|
|
107
|
+
dryRun: argv.dryRun,
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (currentEnvironment === null) {
|
|
112
|
+
throw new Error("ENVIRONMENT_NAME must be set to derive the default Lambda function name (or pass --lambda explicitly).");
|
|
113
|
+
}
|
|
114
|
+
const lambdaFunctionName = argv.lambda ?? defaultLambdaFunctionName(currentEnvironment);
|
|
115
|
+
await (0, sync_schedules_via_lambda_1.syncSchedulesViaLambda)(composer, {
|
|
116
|
+
schedules: options.schedules,
|
|
117
|
+
lambdaFunctionName,
|
|
118
|
+
currentEnvironment,
|
|
119
|
+
dryRun: argv.dryRun,
|
|
120
|
+
mode: argv.mode,
|
|
121
|
+
region: argv.region,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=sync-schedules-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-schedules-cli.js","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/sync-schedules-cli.ts"],"names":[],"mappings":";;;;;AAoFA,kDAoEC;AAxJD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,kDAA0B;AAC1B,2CAAwC;AAGxC,qDAAmD;AACnD,2EAAqE;AAErE;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,WAAmB;IACpD,OAAO,WAAW,WAAW,uBAAuB,CAAC;AACvD,CAAC;AAoBD;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CACvC,QAA4B,EAC5B,OAAmC;IAEnC,MAAM,IAAI,GAAG,MAAM,IAAA,eAAK,EAAC,OAAO,CAAC,IAAI,IAAI,I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CAAC;IACJ,CAAC;IAED,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,IAAI,yBAAyB,CAAC,kBAAkB,CAAC,CAAC;IAExF,MAAM,IAAA,kDAAsB,EAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,kBAAkB;QAClB,kBAAkB;QAClB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Composer } from "../../context-provider";
|
|
2
|
+
import type { ScheduleDefinition } from "../schedule/define-schedule";
|
|
3
|
+
/**
|
|
4
|
+
* Options for `syncSchedulesViaLambda`.
|
|
5
|
+
*/
|
|
6
|
+
export interface SyncSchedulesViaLambdaOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Schedule definitions to reconcile. Typically the values of a
|
|
9
|
+
* composer-instance's `schedules/` barrel filtered by `isScheduleDefinition`.
|
|
10
|
+
*/
|
|
11
|
+
schedules: ScheduleDefinition[];
|
|
12
|
+
/**
|
|
13
|
+
* Name of the schedule-sync Lambda to invoke (e.g.
|
|
14
|
+
* `"loti-ic-prod-temporalschedulesync"`).
|
|
15
|
+
*
|
|
16
|
+
* Ignored in `"emit"` mode but still required for type-safety.
|
|
17
|
+
*/
|
|
18
|
+
lambdaFunctionName: string;
|
|
19
|
+
/**
|
|
20
|
+
* Current environment used to filter schedules by their `environments`
|
|
21
|
+
* allowlist.
|
|
22
|
+
*
|
|
23
|
+
* @default process.env.ENVIRONMENT_NAME
|
|
24
|
+
*/
|
|
25
|
+
currentEnvironment?: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* If true, the Lambda runs the reconciliation in dry-run mode (logs what
|
|
28
|
+
* would change, touches nothing on the server).
|
|
29
|
+
*
|
|
30
|
+
* @default process.env.COMPOSER_SCHEDULE_SYNC_DRY_RUN === "true"
|
|
31
|
+
*/
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* `"invoke"` calls the Lambda synchronously; `"emit"` prints the payload
|
|
35
|
+
* to stdout and exits without invoking.
|
|
36
|
+
*
|
|
37
|
+
* @default "invoke"
|
|
38
|
+
*/
|
|
39
|
+
mode?: "invoke" | "emit";
|
|
40
|
+
/**
|
|
41
|
+
* AWS region for the Lambda client.
|
|
42
|
+
*
|
|
43
|
+
* @default "us-east-1"
|
|
44
|
+
*/
|
|
45
|
+
region?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Syncs composer schedules by invoking a schedule-sync Lambda (or emitting
|
|
49
|
+
* the payload to stdout).
|
|
50
|
+
*
|
|
51
|
+
* @param composer - Composer instance providing the namespace + logger
|
|
52
|
+
* @param options - Schedules, Lambda function name, and mode/region/env flags
|
|
53
|
+
*/
|
|
54
|
+
export declare function syncSchedulesViaLambda<TContext>(composer: Composer<TContext>, options: SyncSchedulesViaLambdaOptions): Promise<void>;
|
|
55
|
+
//# sourceMappingURL=sync-schedules-via-lambda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-schedules-via-lambda.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/sync-schedules-via-lambda.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AActE;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAEhC;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAEzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EACnD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,IAAI,CAAC,CAiHf"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncSchedulesViaLambda = syncSchedulesViaLambda;
|
|
4
|
+
/**
|
|
5
|
+
* Sync Schedules via Lambda
|
|
6
|
+
*
|
|
7
|
+
* Framework helper that reconciles composer schedules by invoking a
|
|
8
|
+
* `schedule-sync` Lambda rather than connecting to the Temporal server
|
|
9
|
+
* directly. The Lambda receives `{ namespace, schedules, dryRun }` as JSON,
|
|
10
|
+
* calls the reconciler (`syncSchedules`), and returns a diff summary.
|
|
11
|
+
*
|
|
12
|
+
* This is the intended deploy-time path: CI assumes an AWS role with
|
|
13
|
+
* `lambda:InvokeFunction` permission and runs this helper from a
|
|
14
|
+
* composer-instance script (e.g. `@loti/composer-ix` `sync-schedules`).
|
|
15
|
+
*
|
|
16
|
+
* Supports two modes:
|
|
17
|
+
* - `"invoke"` (default): invokes the Lambda synchronously, logs tail logs
|
|
18
|
+
* from the response, and exits `1` on any failure path (FunctionError,
|
|
19
|
+
* per-schedule errors, or SDK errors).
|
|
20
|
+
* - `"emit"`: prints the JSON payload to stdout and exits `0` without
|
|
21
|
+
* invoking. Useful for capturing the payload as a CI artifact or for
|
|
22
|
+
* manually passing it through an approval gate.
|
|
23
|
+
*
|
|
24
|
+
* ## Usage
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { isScheduleDefinition, syncSchedulesViaLambda } from "@lotiai/composer";
|
|
28
|
+
* import { composer } from "./my-app-composer";
|
|
29
|
+
* import * as schedules from "./schedules";
|
|
30
|
+
*
|
|
31
|
+
* await syncSchedulesViaLambda(composer, {
|
|
32
|
+
* schedules: Object.values(schedules).filter(isScheduleDefinition),
|
|
33
|
+
* lambdaFunctionName: "loti-ic-prod-temporalschedulesync",
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @module sync-schedules-via-lambda
|
|
38
|
+
*/
|
|
39
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
40
|
+
const DEFAULT_REGION = "us-east-1";
|
|
41
|
+
/**
|
|
42
|
+
* Syncs composer schedules by invoking a schedule-sync Lambda (or emitting
|
|
43
|
+
* the payload to stdout).
|
|
44
|
+
*
|
|
45
|
+
* @param composer - Composer instance providing the namespace + logger
|
|
46
|
+
* @param options - Schedules, Lambda function name, and mode/region/env flags
|
|
47
|
+
*/
|
|
48
|
+
async function syncSchedulesViaLambda(composer, options) {
|
|
49
|
+
const logger = composer.logger;
|
|
50
|
+
const { namespace } = composer.temporal;
|
|
51
|
+
const currentEnvironment = options.currentEnvironment ?? process.env.ENVIRONMENT_NAME ?? null;
|
|
52
|
+
const dryRun = options.dryRun ?? process.env.COMPOSER_SCHEDULE_SYNC_DRY_RUN === "true";
|
|
53
|
+
const mode = options.mode ?? "invoke";
|
|
54
|
+
const region = options.region ?? DEFAULT_REGION;
|
|
55
|
+
if (currentEnvironment === null && options.schedules.length > 0) {
|
|
56
|
+
logger.error("Cannot sync schedules: no current environment was provided", {
|
|
57
|
+
hint: "Set ENVIRONMENT_NAME or pass options.currentEnvironment to syncSchedulesViaLambda",
|
|
58
|
+
scheduleCount: options.schedules.length,
|
|
59
|
+
});
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const activeSchedules = [];
|
|
63
|
+
const skippedSchedules = [];
|
|
64
|
+
for (const schedule of options.schedules) {
|
|
65
|
+
if (currentEnvironment !== null && schedule.environments.includes(currentEnvironment)) {
|
|
66
|
+
activeSchedules.push(schedule);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
skippedSchedules.push({
|
|
70
|
+
scheduleId: schedule.scheduleId,
|
|
71
|
+
environments: schedule.environments,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const payload = {
|
|
76
|
+
namespace,
|
|
77
|
+
schedules: activeSchedules,
|
|
78
|
+
dryRun,
|
|
79
|
+
};
|
|
80
|
+
logger.info("Preparing schedule sync payload", {
|
|
81
|
+
namespace,
|
|
82
|
+
currentEnvironment,
|
|
83
|
+
dryRun,
|
|
84
|
+
mode,
|
|
85
|
+
active: activeSchedules.length,
|
|
86
|
+
skipped: skippedSchedules.length,
|
|
87
|
+
...(mode === "invoke" ? { lambdaFunctionName: options.lambdaFunctionName } : {}),
|
|
88
|
+
});
|
|
89
|
+
for (const { scheduleId, environments } of skippedSchedules) {
|
|
90
|
+
logger.debug("Skipping schedule (not active in current environment)", {
|
|
91
|
+
scheduleId,
|
|
92
|
+
environments,
|
|
93
|
+
currentEnvironment,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (mode === "emit") {
|
|
97
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const client = new client_lambda_1.LambdaClient({ region });
|
|
101
|
+
let response;
|
|
102
|
+
try {
|
|
103
|
+
response = await client.send(new client_lambda_1.InvokeCommand({
|
|
104
|
+
FunctionName: options.lambdaFunctionName,
|
|
105
|
+
Payload: new TextEncoder().encode(JSON.stringify(payload)),
|
|
106
|
+
LogType: "Tail",
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.error("Failed to invoke schedule-sync Lambda", {
|
|
111
|
+
lambdaFunctionName: options.lambdaFunctionName,
|
|
112
|
+
error: error instanceof Error ? error.message : String(error),
|
|
113
|
+
});
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
if (response.LogResult) {
|
|
117
|
+
const logs = Buffer.from(response.LogResult, "base64").toString("utf-8");
|
|
118
|
+
logger.info("Schedule-sync Lambda tail logs", { logs });
|
|
119
|
+
}
|
|
120
|
+
const responsePayload = response.Payload
|
|
121
|
+
? JSON.parse(new TextDecoder().decode(response.Payload))
|
|
122
|
+
: null;
|
|
123
|
+
if (response.FunctionError) {
|
|
124
|
+
logger.error("Schedule-sync Lambda returned FunctionError", {
|
|
125
|
+
functionError: response.FunctionError,
|
|
126
|
+
payload: responsePayload,
|
|
127
|
+
});
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
const result = responsePayload;
|
|
131
|
+
logger.info("Schedule sync complete", {
|
|
132
|
+
namespace,
|
|
133
|
+
dryRun,
|
|
134
|
+
created: result?.created?.length ?? 0,
|
|
135
|
+
updated: result?.updated?.length ?? 0,
|
|
136
|
+
deleted: result?.deleted?.length ?? 0,
|
|
137
|
+
errors: result?.errors?.length ?? 0,
|
|
138
|
+
});
|
|
139
|
+
if (result?.errors && result.errors.length > 0) {
|
|
140
|
+
for (const { scheduleId, error } of result.errors) {
|
|
141
|
+
logger.error("Schedule failed to sync", { scheduleId, error });
|
|
142
|
+
}
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=sync-schedules-via-lambda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-schedules-via-lambda.js","sourceRoot":"","sources":["../../../../src/internal/async/register-scripts/sync-schedules-via-lambda.ts"],"names":[],"mappings":";;AA4GA,wDAoHC;AAhOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,0DAA+F;AAK/F,MAAM,cAAc,GAAG,WAAW,CAAC;AA6DnC;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAC1C,QAA4B,EAC5B,OAAsC;IAEtC,MAAM,MAAM,GAAG,QAAQ,CA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