@yarkivaev/scada 2.5.2 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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); }, ['url', 'config'], modbusResources)],
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'])],
@@ -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
  });