@yarkivaev/scada 2.5.1 → 2.5.3
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 +8 -0
- package/package.json +1 -1
- package/src/application/runtime/pipelineAdapters.js +4 -2
- package/src/infrastructure/ingest/modbus/mx210Tcp.js +2 -2
- package/src/infrastructure/ingest/mqtt/modbusMqtt.js +2 -1
- package/src/infrastructure/ingest/mqtt/modbusPublish.js +1 -0
- package/src/infrastructure/ingest/telemetry/streamNameFromTopic.js +3 -3
- package/src/infrastructure/streams/mqttSink/session.js +5 -0
- package/src/infrastructure/streams/mqttSink.js +1 -0
package/README.md
CHANGED
|
@@ -579,3 +579,11 @@ servers:
|
|
|
579
579
|
```
|
|
580
580
|
|
|
581
581
|
This changes the selected server only; it does not mutate the shared profile.
|
|
582
|
+
|
|
583
|
+
### Central backup freshness
|
|
584
|
+
|
|
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'])],
|
|
@@ -59,12 +59,12 @@ export function mx210Metrics(device, collector) {
|
|
|
59
59
|
* @param {string} name - Stream id (device name in MX210 topics)
|
|
60
60
|
* @param {string} host - Modbus TCP host
|
|
61
61
|
* @param {number} port - Modbus TCP port
|
|
62
|
-
* @returns {object} Stream with name() and open(collector, clock, interval)
|
|
62
|
+
* @returns {object} Stream with family/device name() and open(collector, clock, interval)
|
|
63
63
|
*/
|
|
64
64
|
export default function mx210Tcp(name, host, port) {
|
|
65
65
|
return Object.freeze({
|
|
66
66
|
name() {
|
|
67
|
-
return name
|
|
67
|
+
return `MX210/${name}`;
|
|
68
68
|
},
|
|
69
69
|
open(collector, clk, interval) {
|
|
70
70
|
return modbusSource(
|
|
@@ -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,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Extracts the stream id from a metrics MQTT/AMQP topic path.
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
|
-
* streamNameFromTopic('MX210/m-1/GET/AI1/VALUE') === 'm-1'
|
|
5
|
+
* streamNameFromTopic('MX210/m-1/GET/AI1/VALUE') === 'MX210/m-1'
|
|
6
6
|
*
|
|
7
7
|
* @param {string} topic - Slash-separated topic
|
|
8
|
-
* @returns {string|undefined}
|
|
8
|
+
* @returns {string|undefined} Source-family/device id
|
|
9
9
|
*/
|
|
10
10
|
export default function streamNameFromTopic(topic) {
|
|
11
11
|
if (typeof topic !== 'string' || topic.length === 0) {
|
|
@@ -17,5 +17,5 @@ export default function streamNameFromTopic(topic) {
|
|
|
17
17
|
if (parts.length < 2) {
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
|
-
return parts[1]
|
|
20
|
+
return `${parts[0]}/${parts[1]}`;
|
|
21
21
|
}
|
|
@@ -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
|
});
|