@yarkivaev/scada 2.5.2 → 2.5.4
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/README.md +4 -0
- package/package.json +1 -1
- package/src/application/runtime/pipelineAdapters.js +4 -2
- package/src/application/siteServer.js +1 -1
- package/src/application/supervisorSink.js +2 -1
- package/src/infrastructure/http/plant/routes/stateRoute.js +1 -1
- package/src/infrastructure/ingest/mqtt/modbusMqtt.js +2 -1
- package/src/infrastructure/ingest/mqtt/modbusPublish.js +1 -0
- package/src/infrastructure/streams/mqttSink/session.js +5 -0
- package/src/infrastructure/streams/mqttSink.js +1 -0
package/README.md
CHANGED
|
@@ -583,3 +583,7 @@ This changes the selected server only; it does not mutate the shared profile.
|
|
|
583
583
|
### Central backup freshness
|
|
584
584
|
|
|
585
585
|
Silent Modbus backup sources use `MX210/<device>` freshness identities. AMQP telemetry tracks `<source-family>/<device>`, so cooling for a device cannot hide missing MX210 electrical samples. Measurement topic paths are unchanged. Custom freshness callbacks must pass the source’s full identity to `seen()`.
|
|
586
|
+
|
|
587
|
+
### MQTT publisher recovery
|
|
588
|
+
|
|
589
|
+
An unexpected MQTT publisher close/offline/error retires the session and notifies `onFatal` once. Intentional `stop()` does not notify failure. Modbus runtime tasks propagate publisher failure to collector `/ready` and `/live` (503). Run the collector under its liveness supervisor: it must retire the failed executor and create a fresh one, which reconnects after the broker returns. Uncertain publications are not automatically replayed. Broker restart regression covers failed health, old poll cleanup, and confirmed fresh measurements from the replacement executor.
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ function adapter(factory, required, resourceKeys = () => { return []; }) {
|
|
|
28
28
|
start() {
|
|
29
29
|
context.signal.throwIfAborted();
|
|
30
30
|
if (stopped) { throw new Error('Pipeline stopped'); }
|
|
31
|
-
pipeline ??= factory(configured(spec, context));
|
|
31
|
+
pipeline ??= factory(configured(spec, context), context);
|
|
32
32
|
return pipeline.start();
|
|
33
33
|
},
|
|
34
34
|
stop() { stopped = true; return pipeline?.stop(); }
|
|
@@ -51,7 +51,9 @@ function metrics(spec, factory) {
|
|
|
51
51
|
}
|
|
52
52
|
export default function pipelineAdapters() {
|
|
53
53
|
return new Map([
|
|
54
|
-
['modbus', adapter((spec) => { return modbusPublish(spec.url, spec.config
|
|
54
|
+
['modbus', adapter((spec, context) => { return modbusPublish(spec.url, { ...spec.config, onFatal(error) {
|
|
55
|
+
context.report?.({ state: 'failed', fatal: true, reason: error.code ?? error.name });
|
|
56
|
+
} }); }, ['url', 'config'], modbusResources)],
|
|
55
57
|
['activity', adapter((spec) => { return activityTracking(spec.lokiUrl, spec.clickhouseUrl, spec.query, spec.config); }, ['lokiUrl', 'clickhouseUrl', 'query', 'config'])],
|
|
56
58
|
['amqp-relay', adapter((spec) => { return amqpMqttRelay(spec.url, spec.queue, mqttSink(spec.mqttUrl, spec.options), spec.options); }, ['url', 'queue', 'mqttUrl'])],
|
|
57
59
|
['amqp-metrics', adapter((spec) => { return metrics(spec, (sink) => { return amqpMetricsIngest(spec.url, spec.queue, sink, spec.options); }); }, ['url', 'queue', 'clickhouseUrl', 'table'])],
|
|
@@ -120,7 +120,7 @@ function siteExtraRoutes(catalog, extraRoutes, syncRoutes) {
|
|
|
120
120
|
*/
|
|
121
121
|
export default async function siteServer(config) {
|
|
122
122
|
const env = collectionEnvironment(config);
|
|
123
|
-
const sink = supervisorSink(env);
|
|
123
|
+
const sink = supervisorSink(env, { stateData: config.stateData });
|
|
124
124
|
const ops = bindSiteOperations(sink, config.kindSources || config.operationSources);
|
|
125
125
|
const http = edgeApi(sink.dataAccess, {
|
|
126
126
|
port: sink.apiPort,
|
|
@@ -97,7 +97,8 @@ export default function supervisorSink(env = process.env, options = {}) {
|
|
|
97
97
|
if (cfg.pipeline.transactions.enabled) { cfg.pipeline.onBatch = segmentBatchStats(cfg.pipeline.transactions.statsIntervalMs); }
|
|
98
98
|
const pool = holdClient(new pg.Pool({ connectionString: cfg.postgres, max: cfg.dbPoolMax }));
|
|
99
99
|
const metricsEnabled = cfg.sinkDbProfile === 'edge';
|
|
100
|
-
const
|
|
100
|
+
const data = stateDataFromPool(pool, { metricsEnabled });
|
|
101
|
+
const dataAccess = options.stateData ? options.stateData(data, pool) : data;
|
|
101
102
|
return {
|
|
102
103
|
health: () => {return health.status()},
|
|
103
104
|
apiPort: cfg.apiPort,
|
|
@@ -177,7 +177,8 @@ export default function modbusMqtt(mqtt, devices, config) {
|
|
|
177
177
|
const clk = clock();
|
|
178
178
|
const sink = mqttSink(mqtt, {
|
|
179
179
|
clientId: config.clientId || 'scada-modbus',
|
|
180
|
-
qos: 1
|
|
180
|
+
qos: 1,
|
|
181
|
+
onFatal: config.onFatal
|
|
181
182
|
});
|
|
182
183
|
const collector = ingestBatch(sink, { ...config, size: config.size ?? 5 });
|
|
183
184
|
const sources = buildSources(devices, config, collector, clk);
|
|
@@ -289,6 +289,7 @@ export default function modbusPublish(mqtt, config) {
|
|
|
289
289
|
}));
|
|
290
290
|
return modbusMqtt(mqtt, specs, {
|
|
291
291
|
budget: config.budget,
|
|
292
|
+
onFatal: config.onFatal,
|
|
292
293
|
maxRecords: config.maxRecords,
|
|
293
294
|
maxBytes: config.maxBytes,
|
|
294
295
|
writeTimeoutMs: config.writeTimeoutMs,
|
|
@@ -10,6 +10,11 @@ export function terminate(live, error) {
|
|
|
10
10
|
}), live.options.stopTimeoutMs, 'MQTT disconnect');
|
|
11
11
|
// An event callback cannot surface a rejected shutdown. stop() still returns it.
|
|
12
12
|
void live.closing.catch(() => { return undefined; });
|
|
13
|
+
if (!live.stopping) {
|
|
14
|
+
try { live.options.onFatal?.(error || new Error('MQTT connection closed')); } catch {
|
|
15
|
+
// Observability must not prevent closing the retired session.
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
return live.closing;
|
|
14
19
|
}
|
|
15
20
|
export function connect(live) {
|
|
@@ -46,6 +46,7 @@ export default function mqttSink(url, options = {}) {
|
|
|
46
46
|
write(records, { signal } = {}) { return write(live, records, signal); },
|
|
47
47
|
stop() {
|
|
48
48
|
const stopped = live;
|
|
49
|
+
if (stopped) { stopped.stopping = true; }
|
|
49
50
|
return (stopped ? terminate(stopped, new Error('MQTT sink stopped')) : Promise.resolve()).then(() => {
|
|
50
51
|
if (live === stopped) { live = undefined; }
|
|
51
52
|
});
|