@sixb/cli 0.1.0 → 0.1.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/commands/dev.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/lib/health.d.ts +3 -3
- package/dist/lib/health.d.ts.map +1 -1
- package/dist/lib/loadSixb.d.ts +3 -48
- package/dist/lib/loadSixb.d.ts.map +1 -1
- package/dist/lib/production.d.ts +2 -2
- package/dist/lib/production.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +8 -8
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/shareable-providers.d.ts +3 -3
- package/dist/lib/shareable-providers.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts +2 -2
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +3 -3
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/index.d.ts +1 -13
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/commands/api.tsx +4 -4
- package/src/commands/app.tsx +2 -2
- package/src/commands/atlas.tsx +2 -2
- package/src/commands/check.tsx +1 -1
- package/src/commands/dev.tsx +8 -9
- package/src/commands/orchestrator.tsx +2 -2
- package/src/commands/rules.tsx +2 -2
- package/src/commands/scheduler.tsx +2 -2
- package/src/commands/worker-group.tsx +4 -3
- package/src/commands/worker.tsx +2 -2
- package/src/lib/health.ts +8 -8
- package/src/lib/loadSixb.ts +70 -105
- package/src/lib/production.ts +2 -2
- package/src/lib/runtime.ts +44 -38
- package/src/lib/shareable-providers.ts +6 -6
- package/src/lib/storage-migration.ts +3 -3
- package/src/lib/worker-registry.ts +10 -15
- package/src/ui/index.tsx +0 -69
package/src/lib/health.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkStorageSchema } from "@sixb/core"
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
3
3
|
import { findProcessLocalProviders } from "./shareable-providers"
|
|
4
4
|
|
|
5
5
|
/** An unreachable Postgres waits rather than refusing, so every probe is bounded. */
|
|
@@ -27,11 +27,11 @@ export interface RuntimeCheck {
|
|
|
27
27
|
/**
|
|
28
28
|
* Probes the configured providers with read-only round trips.
|
|
29
29
|
*
|
|
30
|
-
* There is no `events` row because there is no events provider: `
|
|
30
|
+
* There is no `events` row because there is no events provider: `DomainEventService` is built over
|
|
31
31
|
* the broker, so probing both was one round trip reported twice.
|
|
32
32
|
*/
|
|
33
33
|
export async function checkRuntimeHealth(
|
|
34
|
-
sixb:
|
|
34
|
+
sixb: LoadedSixbHost,
|
|
35
35
|
options: RuntimeCheckOptions = {}
|
|
36
36
|
): Promise<RuntimeCheck> {
|
|
37
37
|
const timeoutMs = options.timeoutMs ?? PROBE_TIMEOUT_MS
|
|
@@ -51,7 +51,7 @@ export async function checkRuntimeHealth(
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async function probeStorage(sixb:
|
|
54
|
+
async function probeStorage(sixb: LoadedSixbHost, timeoutMs: number): Promise<ProviderCheck> {
|
|
55
55
|
const name = providerName(sixb.storage)
|
|
56
56
|
const reachable = await probe(() => sixb.storage.ping(), name, timeoutMs)
|
|
57
57
|
if (!reachable.ok) return reachable
|
|
@@ -75,7 +75,7 @@ async function probeStorage(sixb: LoadedSixb, timeoutMs: number): Promise<Provid
|
|
|
75
75
|
: schema
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
async function probeTimeseries(sixb:
|
|
78
|
+
async function probeTimeseries(sixb: LoadedSixbHost): Promise<void> {
|
|
79
79
|
// A read that matches nothing still exercises the telemetry table, which is a
|
|
80
80
|
// different table from the one `ping()` touches.
|
|
81
81
|
await sixb.storage.timeseries.getLatest({
|
|
@@ -86,19 +86,19 @@ async function probeTimeseries(sixb: LoadedSixb): Promise<void> {
|
|
|
86
86
|
})
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
async function probeBroker(sixb:
|
|
89
|
+
async function probeBroker(sixb: LoadedSixbHost): Promise<void> {
|
|
90
90
|
// `latestCursor` is the only read in the broker contract that neither writes nor
|
|
91
91
|
// requires the stream to exist — it answers `undefined` for a missing one.
|
|
92
92
|
await sixb.events.latestCursor()
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
function probeQueues(sixb:
|
|
95
|
+
function probeQueues(sixb: LoadedSixbHost, timeoutMs: number): Promise<ProviderCheck> {
|
|
96
96
|
// Bound to the provider: `probe` calls it as a bare function, and a queues provider
|
|
97
97
|
// that reads its own connection off `this` would see `undefined`.
|
|
98
98
|
return probe(sixb.queues.health.bind(sixb.queues), providerName(sixb.queues), timeoutMs)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function processLocalWarnings(sixb:
|
|
101
|
+
function processLocalWarnings(sixb: LoadedSixbHost): readonly string[] {
|
|
102
102
|
return findProcessLocalProviders(sixb).map(
|
|
103
103
|
(offender) =>
|
|
104
104
|
`${offender.slot} is ${offender.configured}, which only works inside one process. ` +
|
package/src/lib/loadSixb.ts
CHANGED
|
@@ -1,115 +1,33 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url"
|
|
2
|
-
import type {
|
|
3
|
-
ActionDefinition,
|
|
4
|
-
Broker,
|
|
5
|
-
ConnectorAdapter,
|
|
6
|
-
ConnectorClient,
|
|
7
|
-
ConnectorDefinition,
|
|
8
|
-
DatasetDefinition,
|
|
9
|
-
LinkProjectionDefinition,
|
|
10
|
-
ObjectProjectionDefinition,
|
|
11
|
-
OntologyMaintenanceHandle,
|
|
12
|
-
OntologyOperationalStatus,
|
|
13
|
-
PipelineDefinition,
|
|
14
|
-
ProjectionDefinition,
|
|
15
|
-
RuleDefinition,
|
|
16
|
-
ScheduleDefinition,
|
|
17
|
-
SixbReadiness,
|
|
18
|
-
SixbRuntimeContext,
|
|
19
|
-
SyncDefinition,
|
|
20
|
-
TelemetryProjectionDefinition,
|
|
21
|
-
} from "@sixb/core"
|
|
22
|
-
import type { AgentsRuntime } from "@sixb/core/internal/agents"
|
|
23
|
-
import type { AuthRuntime } from "@sixb/core/internal/auth"
|
|
24
|
-
import type { WorkflowsRuntime } from "@sixb/core/internal/workflows"
|
|
25
|
-
import type { ObjectRow } from "@sixb/core/storage"
|
|
2
|
+
import type { SixbHostView } from "@sixb/core"
|
|
26
3
|
|
|
27
|
-
export
|
|
28
|
-
readonly id: string
|
|
29
|
-
readonly broker: Broker
|
|
30
|
-
readonly auth: AuthRuntime
|
|
31
|
-
listObjectTypes(): readonly unknown[]
|
|
32
|
-
listActions(): readonly ActionDefinition[]
|
|
33
|
-
getActionById(actionId: string): ActionDefinition | null
|
|
34
|
-
listSyncs(): readonly SyncDefinition[]
|
|
35
|
-
listPipelines(): readonly PipelineDefinition[]
|
|
36
|
-
getPipelineById(pipelineId: string): PipelineDefinition | null
|
|
37
|
-
listSchedules(): readonly ScheduleDefinition[]
|
|
38
|
-
readonly workflows: WorkflowsRuntime
|
|
39
|
-
readonly agents: AgentsRuntime
|
|
40
|
-
listObjectProjections(): readonly ObjectProjectionDefinition[]
|
|
41
|
-
listLinkProjections(): readonly LinkProjectionDefinition[]
|
|
42
|
-
listTelemetryProjections(): readonly TelemetryProjectionDefinition[]
|
|
43
|
-
listDatasets(): readonly DatasetDefinition[]
|
|
44
|
-
listRules(): readonly RuleDefinition[]
|
|
45
|
-
getDatasetById(datasetId: string): DatasetDefinition | null
|
|
46
|
-
getProjectionById(projectionId: string): ProjectionDefinition | null
|
|
47
|
-
getSyncById(syncId: string): SyncDefinition | null
|
|
48
|
-
getRuleById(ruleId: string): RuleDefinition | null
|
|
49
|
-
listSubTypes(objectTypeId: string): string[]
|
|
50
|
-
connector<TAdapter extends ConnectorAdapter>(
|
|
51
|
-
definition: ConnectorDefinition<string, TAdapter>
|
|
52
|
-
): Promise<ConnectorClient<TAdapter>>
|
|
53
|
-
startScheduler(): Promise<void>
|
|
54
|
-
stopScheduler(): Promise<void>
|
|
55
|
-
startOntologyMaintenance(): Promise<OntologyMaintenanceHandle>
|
|
56
|
-
getOntologyOperationalStatus(): OntologyOperationalStatus
|
|
57
|
-
checkReadiness(): Promise<SixbReadiness>
|
|
58
|
-
disconnectConnectors(): Promise<void>
|
|
59
|
-
closeLogger(): Promise<void>
|
|
60
|
-
closeBroker(): Promise<void>
|
|
61
|
-
list(params: {
|
|
62
|
-
objectTypeIds?: readonly string[]
|
|
63
|
-
limit?: number
|
|
64
|
-
offset?: number
|
|
65
|
-
}): Promise<{ total: number; hasMore: boolean; objects: ObjectRow[] }>
|
|
66
|
-
}
|
|
4
|
+
export type LoadedSixbHost = SixbHostView
|
|
67
5
|
|
|
68
6
|
function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
|
|
69
7
|
return !!value && typeof value === "object" && "then" in value
|
|
70
8
|
}
|
|
71
9
|
|
|
72
|
-
const
|
|
73
|
-
"
|
|
74
|
-
"actionRegistry",
|
|
10
|
+
const REQUIRED_HOST_PROPERTIES = [
|
|
11
|
+
"definitions",
|
|
75
12
|
"events",
|
|
13
|
+
"logging",
|
|
76
14
|
"broker",
|
|
77
15
|
"storage",
|
|
78
16
|
"lakeStorage",
|
|
79
17
|
"blobStorage",
|
|
80
18
|
"queues",
|
|
81
19
|
"auth",
|
|
82
|
-
"
|
|
83
|
-
] as const
|
|
84
|
-
|
|
85
|
-
const REQUIRED_DEFINITION_METHODS = [
|
|
86
|
-
"listObjectTypes",
|
|
87
|
-
"listSubTypes",
|
|
88
|
-
"listActions",
|
|
89
|
-
"getActionById",
|
|
90
|
-
"listSyncs",
|
|
91
|
-
"listPipelines",
|
|
92
|
-
"getPipelineById",
|
|
93
|
-
"listSchedules",
|
|
94
|
-
"listObjectProjections",
|
|
95
|
-
"listLinkProjections",
|
|
96
|
-
"listTelemetryProjections",
|
|
97
|
-
"listDatasets",
|
|
98
|
-
"listRules",
|
|
99
|
-
"getDatasetById",
|
|
100
|
-
"getProjectionById",
|
|
101
|
-
"getSyncById",
|
|
102
|
-
"getRuleById",
|
|
20
|
+
"scheduler",
|
|
103
21
|
] as const
|
|
104
22
|
|
|
105
23
|
const REQUIRED_LIFECYCLE_METHODS = [
|
|
106
|
-
"
|
|
107
|
-
"stopScheduler",
|
|
24
|
+
"withScope",
|
|
108
25
|
"startOntologyMaintenance",
|
|
109
26
|
"getOntologyOperationalStatus",
|
|
110
27
|
"checkReadiness",
|
|
111
|
-
"disconnectConnectors",
|
|
112
28
|
"closeLogger",
|
|
29
|
+
"closeConnectors",
|
|
30
|
+
"closeBlobs",
|
|
113
31
|
"closeBroker",
|
|
114
32
|
] as const
|
|
115
33
|
|
|
@@ -124,52 +42,99 @@ function hasProperties(
|
|
|
124
42
|
return properties.every((property) => property in value)
|
|
125
43
|
}
|
|
126
44
|
|
|
127
|
-
function hasMethods(value:
|
|
128
|
-
|
|
45
|
+
function hasMethods(value: unknown, methods: readonly PropertyKey[]): boolean {
|
|
46
|
+
if (!isRecord(value) && typeof value !== "function") return false
|
|
47
|
+
const candidate = value as Record<PropertyKey, unknown>
|
|
48
|
+
return methods.every((method) => typeof candidate[method] === "function")
|
|
129
49
|
}
|
|
130
50
|
|
|
131
|
-
function
|
|
132
|
-
|
|
51
|
+
function hasDefinitionCatalogs(value: Record<PropertyKey, unknown>): boolean {
|
|
52
|
+
if (!isRecord(value.definitions)) return false
|
|
53
|
+
const definitions = value.definitions
|
|
54
|
+
return (
|
|
55
|
+
isRecord(definitions.ontology) &&
|
|
56
|
+
hasMethods(definitions.ontology, ["listObjectTypes", "getObjectTypeById"]) &&
|
|
57
|
+
isRecord(definitions.actions) &&
|
|
58
|
+
hasMethods(definitions.actions, ["list", "getById", "listGlobal", "listForType"]) &&
|
|
59
|
+
isRecord(definitions.connectors) &&
|
|
60
|
+
hasMethods(definitions.connectors, ["list", "getById"]) &&
|
|
61
|
+
isRecord(definitions.datasets) &&
|
|
62
|
+
hasMethods(definitions.datasets, ["list", "getById"]) &&
|
|
63
|
+
isRecord(definitions.syncs) &&
|
|
64
|
+
hasMethods(definitions.syncs, ["list", "getById"]) &&
|
|
65
|
+
isRecord(definitions.pipelines) &&
|
|
66
|
+
hasMethods(definitions.pipelines, ["list", "getById"]) &&
|
|
67
|
+
isRecord(definitions.schedules) &&
|
|
68
|
+
hasMethods(definitions.schedules, ["list", "getById"]) &&
|
|
69
|
+
isRecord(definitions.rules) &&
|
|
70
|
+
hasMethods(definitions.rules, ["list", "getById"]) &&
|
|
71
|
+
isRecord(definitions.projections) &&
|
|
72
|
+
hasMethods(definitions.projections, [
|
|
73
|
+
"list",
|
|
74
|
+
"listObjects",
|
|
75
|
+
"listLinks",
|
|
76
|
+
"listTelemetry",
|
|
77
|
+
"getById",
|
|
78
|
+
]) &&
|
|
79
|
+
isRecord(definitions.workflows) &&
|
|
80
|
+
hasMethods(definitions.workflows, ["list", "getById"]) &&
|
|
81
|
+
isRecord(definitions.agents) &&
|
|
82
|
+
hasMethods(definitions.agents, ["list", "getById"]) &&
|
|
83
|
+
isRecord(definitions.security) &&
|
|
84
|
+
hasMethods(definitions.security, [
|
|
85
|
+
"listGroups",
|
|
86
|
+
"getGroupById",
|
|
87
|
+
"listRoles",
|
|
88
|
+
"getRoleById",
|
|
89
|
+
"listResolvedRoles",
|
|
90
|
+
"listMembershipPolicies",
|
|
91
|
+
"getMembershipPolicyById",
|
|
92
|
+
])
|
|
93
|
+
)
|
|
133
94
|
}
|
|
134
95
|
|
|
135
|
-
function
|
|
96
|
+
function isSixbHost(value: unknown): value is LoadedSixbHost {
|
|
136
97
|
if (!isRecord(value)) return false
|
|
137
98
|
|
|
138
99
|
return (
|
|
139
100
|
typeof value.id === "string" &&
|
|
140
101
|
typeof value.projectId === "string" &&
|
|
141
|
-
hasProperties(value,
|
|
142
|
-
hasMethods(value, REQUIRED_DEFINITION_METHODS) &&
|
|
102
|
+
hasProperties(value, REQUIRED_HOST_PROPERTIES) &&
|
|
143
103
|
hasMethods(value, REQUIRED_LIFECYCLE_METHODS) &&
|
|
144
|
-
|
|
145
|
-
|
|
104
|
+
hasDefinitionCatalogs(value) &&
|
|
105
|
+
isRecord(value.logging) &&
|
|
106
|
+
hasMethods(value.logging, ["startExecution", "read", "tail"]) &&
|
|
107
|
+
isRecord(value.blobStorage) &&
|
|
108
|
+
hasMethods(value.blobStorage, ["put", "open", "stat"]) &&
|
|
109
|
+
isRecord(value.scheduler) &&
|
|
110
|
+
hasMethods(value.scheduler, ["start", "stop"])
|
|
146
111
|
)
|
|
147
112
|
}
|
|
148
113
|
|
|
149
|
-
export async function loadSixbFromEntry(entry: string): Promise<
|
|
114
|
+
export async function loadSixbFromEntry(entry: string): Promise<LoadedSixbHost> {
|
|
150
115
|
const module = (await import(pathToFileURL(entry).href)) as Record<string, unknown>
|
|
151
116
|
const candidate = module.sixb ?? module.default
|
|
152
117
|
|
|
153
|
-
if (
|
|
118
|
+
if (isSixbHost(candidate)) {
|
|
154
119
|
return candidate
|
|
155
120
|
}
|
|
156
121
|
|
|
157
122
|
if (typeof candidate === "function") {
|
|
158
123
|
const created = (candidate as () => unknown)()
|
|
159
124
|
const resolved = isPromiseLike(created) ? await created : created
|
|
160
|
-
if (
|
|
125
|
+
if (isSixbHost(resolved)) {
|
|
161
126
|
return resolved
|
|
162
127
|
}
|
|
163
128
|
}
|
|
164
129
|
|
|
165
130
|
if (isPromiseLike(candidate)) {
|
|
166
131
|
const resolved = await candidate
|
|
167
|
-
if (
|
|
132
|
+
if (isSixbHost(resolved)) {
|
|
168
133
|
return resolved
|
|
169
134
|
}
|
|
170
135
|
}
|
|
171
136
|
|
|
172
137
|
throw new Error(
|
|
173
|
-
"Could not load Sixb
|
|
138
|
+
"Could not load a Sixb host from entry. Export `sixb` (or default) as a SixbHost or Promise<SixbHost>."
|
|
174
139
|
)
|
|
175
140
|
}
|
package/src/lib/production.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises"
|
|
2
2
|
import { basename, dirname, resolve, sep } from "node:path"
|
|
3
|
-
import { type
|
|
3
|
+
import { type LoadedSixbHost, loadSixbFromEntry } from "./loadSixb"
|
|
4
4
|
import type { ProductionRole } from "./production-roles"
|
|
5
5
|
import { assertShareableProviders } from "./shareable-providers"
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@ export async function resolveRuntimeEntry(options: RuntimeEntryOptions = {}): Pr
|
|
|
36
36
|
|
|
37
37
|
export async function loadProductionSixb(
|
|
38
38
|
options: ProductionRuntimeOptions
|
|
39
|
-
): Promise<{ entry: string; sixb:
|
|
39
|
+
): Promise<{ entry: string; sixb: LoadedSixbHost; projectRoot: string; buildOutdir: string }> {
|
|
40
40
|
const entry = await resolveRuntimeEntry(options)
|
|
41
41
|
const sixb = await loadSixbFromEntry(entry)
|
|
42
42
|
assertShareableProviders(sixb, options.role)
|
package/src/lib/runtime.ts
CHANGED
|
@@ -3,8 +3,14 @@ import { ActionWorker } from "@sixb/action-worker"
|
|
|
3
3
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
4
4
|
import { migrateStorage } from "@sixb/core"
|
|
5
5
|
import { flushSixbErrors } from "@sixb/core/internal/error-reporting"
|
|
6
|
-
import {
|
|
6
|
+
import { PipelineRunDispatcher } from "@sixb/core/internal/pipelines"
|
|
7
|
+
import {
|
|
8
|
+
getProjectionDispatchDescriptors,
|
|
9
|
+
ProjectionRunDispatcher,
|
|
10
|
+
} from "@sixb/core/internal/projections"
|
|
11
|
+
import { SyncRunDispatcher } from "@sixb/core/internal/syncs"
|
|
7
12
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
13
|
+
import { WorkflowRunDispatcher } from "@sixb/core/internal/workflows"
|
|
8
14
|
import { assertLakeDatasetDefinitionsCompatible } from "@sixb/core/lake-storage"
|
|
9
15
|
import {
|
|
10
16
|
type CompileRoutesDiagnostic,
|
|
@@ -16,7 +22,7 @@ import { ProjectionWorker } from "@sixb/projection-worker"
|
|
|
16
22
|
import { RulesWorker } from "@sixb/rules-worker"
|
|
17
23
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
18
24
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
19
|
-
import type {
|
|
25
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
20
26
|
|
|
21
27
|
export function waitForWorkerFailure(worker: Worker | null | undefined): Promise<never> {
|
|
22
28
|
return new Promise<never>((_resolve, reject) => {
|
|
@@ -67,20 +73,20 @@ export interface RunningOrchestratorRuntime {
|
|
|
67
73
|
stop(): Promise<void>
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
export async function migrateRuntimeStorage(sixb:
|
|
76
|
+
export async function migrateRuntimeStorage(sixb: LoadedSixbHost): Promise<void> {
|
|
71
77
|
await migrateStorage(sixb.storage)
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
export async function checkRuntimeLakeDefinitions(sixb:
|
|
80
|
+
export async function checkRuntimeLakeDefinitions(sixb: LoadedSixbHost): Promise<void> {
|
|
75
81
|
await assertLakeDatasetDefinitionsCompatible({
|
|
76
82
|
lakeStorage: sixb.lakeStorage,
|
|
77
|
-
definitions: sixb.
|
|
83
|
+
definitions: sixb.definitions.datasets.list(),
|
|
78
84
|
})
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
export async function stopSixbProviders(sixb:
|
|
87
|
+
export async function stopSixbProviders(sixb: LoadedSixbHost): Promise<void> {
|
|
82
88
|
await stopQuietly(() => flushSixbErrors(sixb))
|
|
83
|
-
await stopQuietly(() => sixb.
|
|
89
|
+
await stopQuietly(() => sixb.closeConnectors())
|
|
84
90
|
await stopQuietly(() => closeProvider(sixb.queues))
|
|
85
91
|
// Stop tracked outbox publication before closing the storage it claims from.
|
|
86
92
|
await stopQuietly(() => sixb.closeBroker())
|
|
@@ -88,14 +94,14 @@ export async function stopSixbProviders(sixb: LoadedSixb): Promise<void> {
|
|
|
88
94
|
await stopQuietly(() => flushSixbErrors(sixb))
|
|
89
95
|
await stopQuietly(() => closeProvider(sixb.storage))
|
|
90
96
|
await stopQuietly(() => closeProvider(sixb.lakeStorage))
|
|
91
|
-
await stopQuietly(() =>
|
|
97
|
+
await stopQuietly(() => sixb.closeBlobs())
|
|
92
98
|
await stopQuietly(() => sixb.closeLogger())
|
|
93
99
|
}
|
|
94
100
|
|
|
95
|
-
export async function startRulesRuntime(sixb:
|
|
101
|
+
export async function startRulesRuntime(sixb: LoadedSixbHost): Promise<RunningRulesRuntime> {
|
|
96
102
|
let rulesWorker: RulesWorker | null = null
|
|
97
103
|
|
|
98
|
-
if (sixb.
|
|
104
|
+
if (sixb.definitions.rules.list().length > 0) {
|
|
99
105
|
rulesWorker = new RulesWorker(sixb)
|
|
100
106
|
await rulesWorker.start()
|
|
101
107
|
}
|
|
@@ -108,47 +114,50 @@ export async function startRulesRuntime(sixb: LoadedSixb): Promise<RunningRulesR
|
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
export async function startSchedulerRuntime(
|
|
112
|
-
|
|
117
|
+
export async function startSchedulerRuntime(
|
|
118
|
+
sixb: LoadedSixbHost
|
|
119
|
+
): Promise<RunningSchedulerRuntime> {
|
|
120
|
+
await sixb.scheduler.start()
|
|
113
121
|
|
|
114
122
|
return {
|
|
115
123
|
async stop() {
|
|
116
|
-
await stopQuietly(() => sixb.
|
|
124
|
+
await stopQuietly(() => sixb.scheduler.stop())
|
|
117
125
|
},
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
export async function startOrchestratorRuntime(
|
|
122
|
-
sixb:
|
|
130
|
+
sixb: LoadedSixbHost
|
|
123
131
|
): Promise<RunningOrchestratorRuntime> {
|
|
124
132
|
const projections = getProjectionDispatchDescriptors(sixb)
|
|
125
133
|
const { routes, diagnostics } = compileRoutesWithDiagnostics({
|
|
126
|
-
schedules: sixb.
|
|
127
|
-
syncs: sixb.
|
|
128
|
-
pipelines: sixb.
|
|
134
|
+
schedules: sixb.definitions.schedules.list(),
|
|
135
|
+
syncs: sixb.definitions.syncs.list(),
|
|
136
|
+
pipelines: sixb.definitions.pipelines.list(),
|
|
129
137
|
projections,
|
|
130
|
-
workflows: sixb.workflows.list(),
|
|
138
|
+
workflows: sixb.definitions.workflows.list(),
|
|
131
139
|
})
|
|
132
140
|
const warnings = diagnostics.map(formatRouteDiagnosticWarning)
|
|
133
141
|
let orchestratorWorker: OrchestratorWorker | null = null
|
|
134
142
|
|
|
135
143
|
if (routes.size > 0) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
throw new Error(
|
|
139
|
-
"[SixbCLI] Projection dispatch requires storage.projectionRuns for durable reconciliation."
|
|
140
|
-
)
|
|
144
|
+
if (projections.length > 0 && !sixb.storage.projectionRuns) {
|
|
145
|
+
throw new Error("[SixbCLI] Projection dispatch requires storage.projectionRuns.")
|
|
141
146
|
}
|
|
142
|
-
const
|
|
143
|
-
projections.length > 0
|
|
144
|
-
? { lakeStorage: sixb.lakeStorage, projectionRuns }
|
|
145
|
-
: undefined
|
|
147
|
+
const projectionReconciliation =
|
|
148
|
+
projections.length > 0 ? { lakeStorage: sixb.lakeStorage } : undefined
|
|
146
149
|
orchestratorWorker = new OrchestratorWorker({
|
|
147
150
|
projectId: sixb.id,
|
|
148
151
|
events: sixb.events,
|
|
149
152
|
queues: sixb.queues,
|
|
150
153
|
routes,
|
|
151
|
-
|
|
154
|
+
dispatchers: {
|
|
155
|
+
syncs: new SyncRunDispatcher(sixb),
|
|
156
|
+
pipelines: new PipelineRunDispatcher(sixb),
|
|
157
|
+
projections: new ProjectionRunDispatcher(sixb),
|
|
158
|
+
workflows: new WorkflowRunDispatcher(sixb),
|
|
159
|
+
},
|
|
160
|
+
...(projectionReconciliation ? { projectionReconciliation } : {}),
|
|
152
161
|
})
|
|
153
162
|
await orchestratorWorker.start()
|
|
154
163
|
}
|
|
@@ -189,7 +198,7 @@ export async function startOrchestratorRuntime(
|
|
|
189
198
|
* 10. Runtime providers (connectors, broker)
|
|
190
199
|
*/
|
|
191
200
|
export async function startSixbRuntime(
|
|
192
|
-
sixb:
|
|
201
|
+
sixb: LoadedSixbHost,
|
|
193
202
|
options: StartSixbRuntimeOptions = {}
|
|
194
203
|
): Promise<RunningSixbRuntime> {
|
|
195
204
|
await migrateRuntimeStorage(sixb)
|
|
@@ -226,38 +235,35 @@ export async function startSixbRuntime(
|
|
|
226
235
|
rulesWorker = rulesRuntime.rulesWorker
|
|
227
236
|
|
|
228
237
|
if (options.cohostWorkers) {
|
|
229
|
-
if (sixb.
|
|
238
|
+
if (sixb.definitions.actions.list().length > 0) {
|
|
230
239
|
actionWorker = new ActionWorker(sixb)
|
|
231
240
|
await actionWorker.start()
|
|
232
241
|
}
|
|
233
242
|
|
|
234
|
-
if (sixb.agents.list().length > 0 && sixb.storage.agents) {
|
|
243
|
+
if (sixb.definitions.agents.list().length > 0 && sixb.storage.agents) {
|
|
235
244
|
agentWorker = new AgentWorker(sixb, {
|
|
236
245
|
apiBaseUrl: requireAgentApiBaseUrl(options.agentApiBaseUrl),
|
|
237
246
|
})
|
|
238
247
|
await agentWorker.start()
|
|
239
248
|
}
|
|
240
249
|
|
|
241
|
-
const projectionCount =
|
|
242
|
-
sixb.listObjectProjections().length +
|
|
243
|
-
sixb.listLinkProjections().length +
|
|
244
|
-
sixb.listTelemetryProjections().length
|
|
250
|
+
const projectionCount = sixb.definitions.projections.list().length
|
|
245
251
|
if (projectionCount > 0) {
|
|
246
252
|
projectionWorker = new ProjectionWorker(sixb)
|
|
247
253
|
await projectionWorker.start()
|
|
248
254
|
}
|
|
249
255
|
|
|
250
|
-
if (sixb.
|
|
256
|
+
if (sixb.definitions.pipelines.list().length > 0) {
|
|
251
257
|
pipelineWorker = new PipelineWorker(sixb)
|
|
252
258
|
await pipelineWorker.start()
|
|
253
259
|
}
|
|
254
260
|
|
|
255
|
-
if (sixb.workflows.list().length > 0) {
|
|
261
|
+
if (sixb.definitions.workflows.list().length > 0) {
|
|
256
262
|
workflowWorker = new WorkflowWorker(sixb)
|
|
257
263
|
await workflowWorker.start()
|
|
258
264
|
}
|
|
259
265
|
|
|
260
|
-
if (sixb.
|
|
266
|
+
if (sixb.definitions.syncs.list().length > 0) {
|
|
261
267
|
syncWorker = new SyncWorker(sixb)
|
|
262
268
|
await syncWorker.start()
|
|
263
269
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Broker, Queues } from "@sixb/core"
|
|
2
2
|
import { SixbCliError } from "./errors"
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
4
|
import { type ProductionRole, productionRoleFacts } from "./production-roles"
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -13,17 +13,17 @@ import { type ProductionRole, productionRoleFacts } from "./production-roles"
|
|
|
13
13
|
const SLOTS = [
|
|
14
14
|
{
|
|
15
15
|
name: "queues",
|
|
16
|
-
get: (sixb:
|
|
16
|
+
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.queues,
|
|
17
17
|
replacements: "@sixb/bullmq",
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
name: "broker",
|
|
21
|
-
get: (sixb:
|
|
21
|
+
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.broker,
|
|
22
22
|
replacements: "@sixb/redis or @sixb/nats",
|
|
23
23
|
},
|
|
24
24
|
] as const
|
|
25
25
|
|
|
26
|
-
function isProcessLocal(slot: (typeof SLOTS)[number], sixb:
|
|
26
|
+
function isProcessLocal(slot: (typeof SLOTS)[number], sixb: LoadedSixbHost): boolean {
|
|
27
27
|
return slot.get(sixb).scope === "process"
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ export interface ProcessLocalProvider {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** The same detection as {@link assertShareableProviders}, without the refusal. */
|
|
39
|
-
export function findProcessLocalProviders(sixb:
|
|
39
|
+
export function findProcessLocalProviders(sixb: LoadedSixbHost): readonly ProcessLocalProvider[] {
|
|
40
40
|
return SLOTS.filter((slot) => isProcessLocal(slot, sixb)).map((slot) => ({
|
|
41
41
|
slot: slot.name,
|
|
42
42
|
configured: slot.get(sixb).constructor?.name ?? "a process-local provider",
|
|
@@ -51,7 +51,7 @@ export function findProcessLocalProviders(sixb: LoadedSixb): readonly ProcessLoc
|
|
|
51
51
|
* the orchestrator enqueues, the worker polls an empty queue, and nothing reports a problem.
|
|
52
52
|
* Throws rather than warns, because an inert deployment is indistinguishable from an idle one.
|
|
53
53
|
*/
|
|
54
|
-
export function assertShareableProviders(sixb:
|
|
54
|
+
export function assertShareableProviders(sixb: LoadedSixbHost, role: ProductionRole): void {
|
|
55
55
|
if (!productionRoleFacts(role).onEventPlane) return
|
|
56
56
|
|
|
57
57
|
for (const offender of findProcessLocalProviders(sixb)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { migrateStorage } from "@sixb/core"
|
|
2
2
|
import { SixbCliError } from "./errors"
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
4
|
import type { StorageSchemaRole } from "./production-roles"
|
|
5
5
|
|
|
6
6
|
/** Set to `1` to start a role without bringing the storage schema up to date. */
|
|
@@ -46,7 +46,7 @@ export interface RoleStorageMigration {
|
|
|
46
46
|
* passed through raw.
|
|
47
47
|
*/
|
|
48
48
|
export async function migrateStorageForRole(
|
|
49
|
-
sixb:
|
|
49
|
+
sixb: LoadedSixbHost,
|
|
50
50
|
options: RoleStorageMigrationOptions
|
|
51
51
|
): Promise<RoleStorageMigration> {
|
|
52
52
|
const { role } = options
|
|
@@ -84,7 +84,7 @@ export async function migrateStorageForRole(
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
async function runMigration(sixb:
|
|
87
|
+
async function runMigration(sixb: LoadedSixbHost, role: StorageSchemaRole) {
|
|
88
88
|
try {
|
|
89
89
|
return await migrateStorage(sixb.storage)
|
|
90
90
|
} catch (error) {
|
|
@@ -6,7 +6,7 @@ import { ProjectionWorker } from "@sixb/projection-worker"
|
|
|
6
6
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
7
7
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
8
8
|
import { SixbCliError } from "./errors"
|
|
9
|
-
import type {
|
|
9
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
10
10
|
import { configuredOrigin } from "./public-origin"
|
|
11
11
|
|
|
12
12
|
export interface WorkerCreationOptions {
|
|
@@ -14,7 +14,7 @@ export interface WorkerCreationOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface WorkerFactory {
|
|
17
|
-
readonly create: (sixb:
|
|
17
|
+
readonly create: (sixb: LoadedSixbHost, options: WorkerCreationOptions) => Worker
|
|
18
18
|
/**
|
|
19
19
|
* Why this worker cannot be constructed with the given options, or `null` when it can.
|
|
20
20
|
* Asked before anything is constructed, so a group names every reason at once.
|
|
@@ -55,7 +55,7 @@ const workerFactories: Record<string, WorkerFactory> = {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function createWorkerForType(
|
|
58
|
-
sixb:
|
|
58
|
+
sixb: LoadedSixbHost,
|
|
59
59
|
workerType: string,
|
|
60
60
|
options: WorkerCreationOptions = {}
|
|
61
61
|
): Worker {
|
|
@@ -139,35 +139,30 @@ export function assertWorkerInputs(input: WorkerGroupInputs): void {
|
|
|
139
139
|
})
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export function resolveRegisteredWorkerTypes(sixb:
|
|
142
|
+
export function resolveRegisteredWorkerTypes(sixb: LoadedSixbHost): readonly string[] {
|
|
143
143
|
const workerTypes: string[] = []
|
|
144
144
|
|
|
145
|
-
if (sixb.
|
|
145
|
+
if (sixb.definitions.syncs.list().length > 0) {
|
|
146
146
|
workerTypes.push("sync")
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
if (sixb.
|
|
149
|
+
if (sixb.definitions.pipelines.list().length > 0) {
|
|
150
150
|
workerTypes.push("pipeline")
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
if (
|
|
154
|
-
sixb.listObjectProjections().length +
|
|
155
|
-
sixb.listLinkProjections().length +
|
|
156
|
-
sixb.listTelemetryProjections().length >
|
|
157
|
-
0
|
|
158
|
-
) {
|
|
153
|
+
if (sixb.definitions.projections.list().length > 0) {
|
|
159
154
|
workerTypes.push("projection")
|
|
160
155
|
}
|
|
161
156
|
|
|
162
|
-
if (sixb.
|
|
157
|
+
if (sixb.definitions.actions.list().length > 0) {
|
|
163
158
|
workerTypes.push("action")
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
if (sixb.agents.list().length > 0 && sixb.storage.agents) {
|
|
161
|
+
if (sixb.definitions.agents.list().length > 0 && sixb.storage.agents) {
|
|
167
162
|
workerTypes.push("agent")
|
|
168
163
|
}
|
|
169
164
|
|
|
170
|
-
if (sixb.workflows.list().length > 0) {
|
|
165
|
+
if (sixb.definitions.workflows.list().length > 0) {
|
|
171
166
|
workerTypes.push("workflow")
|
|
172
167
|
}
|
|
173
168
|
|