@yarkivaev/scada 2.3.83 → 2.3.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.3.83",
3
+ "version": "2.3.85",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@ export default function segmentNormalize(parsed) {
17
17
  const hasOpts = Array.isArray(parsed.options) && parsed.options.length > 0;
18
18
  const resolved = typeof parsed.resolved === 'boolean' ? parsed.resolved : !hasOpts;
19
19
  return {
20
- type: parsed.type,
20
+ type: parsed.type || 'segment',
21
21
  machine: parsed.machine,
22
22
  name: parsed.name,
23
23
  kind: typeof parsed.kind === 'string' && parsed.kind.length > 0 ? parsed.kind : 'phase',
@@ -153,6 +153,8 @@ export default function segmentCoalesce(codec, options = {}) {
153
153
  const ctx = { api, lane, codec, size, intervalMs };
154
154
  lane.queue = lane.queue.then(() => {
155
155
  return step(ctx, envelope, parsed);
156
+ }).catch(() => {
157
+ return undefined;
156
158
  });
157
159
  return lane.queue;
158
160
  },
@@ -13,21 +13,21 @@
13
13
  export default async function abutSegments(pool, budgetSeconds) {
14
14
  await pool.query(
15
15
  `UPDATE segments AS left_row
16
- SET end_time = right_row.start_time,
17
- duration = EXTRACT(EPOCH FROM (right_row.start_time - left_row.start_time))
18
- FROM LATERAL (
19
- SELECT next.start_time, next.name
20
- FROM segments AS next
21
- WHERE next.machine = left_row.machine
22
- AND next.kind = left_row.kind
23
- AND next.start_time > left_row.start_time
24
- ORDER BY next.start_time
25
- LIMIT 1
26
- ) AS right_row
27
- WHERE left_row.duration > 0
28
- AND left_row.name = right_row.name
29
- AND right_row.start_time > left_row.end_time
30
- AND right_row.start_time - left_row.end_time <= make_interval(secs => $1)`,
16
+ SET end_time = next_row.next_start,
17
+ duration = EXTRACT(EPOCH FROM (next_row.next_start - left_row.start_time))
18
+ FROM (
19
+ SELECT machine, kind, start_time,
20
+ lead(start_time) OVER (PARTITION BY machine, kind ORDER BY start_time) AS next_start,
21
+ lead(name) OVER (PARTITION BY machine, kind ORDER BY start_time) AS next_name
22
+ FROM segments
23
+ ) AS next_row
24
+ WHERE left_row.machine = next_row.machine
25
+ AND left_row.kind = next_row.kind
26
+ AND left_row.start_time = next_row.start_time
27
+ AND left_row.duration > 0
28
+ AND left_row.name = next_row.next_name
29
+ AND next_row.next_start > left_row.end_time
30
+ AND next_row.next_start - left_row.end_time <= make_interval(secs => $1)`,
31
31
  [budgetSeconds]
32
32
  );
33
33
  }
@@ -42,14 +42,24 @@ function segmentRow(parsed, startTime, endTime) {
42
42
  return row;
43
43
  }
44
44
 
45
+ function emitPiece(bus, piece) {
46
+ const times = timestamps(piece);
47
+ bus.emit({ type: 'created', segment: segmentRow(piece, times.startTime, times.endTime) });
48
+ }
49
+
45
50
  function consume(raw, buses) {
46
51
  const parsed = JSON.parse(raw.payload);
47
52
  const bus = buses[parsed.machine];
48
53
  if (!bus) {
49
54
  return;
50
55
  }
51
- const { startTime, endTime } = timestamps(parsed);
52
- bus.emit({ type: 'created', segment: segmentRow(parsed, startTime, endTime) });
56
+ if (parsed.type === 'split-family' && Array.isArray(parsed.pieces)) {
57
+ parsed.pieces.forEach((piece) => {
58
+ emitPiece(bus, piece);
59
+ });
60
+ return;
61
+ }
62
+ emitPiece(bus, parsed);
53
63
  }
54
64
 
55
65
  /**
@@ -57,6 +67,8 @@ function consume(raw, buses) {
57
67
  *
58
68
  * Subscribes to STOMP segment exchange and emits created events
59
69
  * on per-machine timeline pubsub buses for SSE delivery.
70
+ * A split-family envelope emits one event per piece. The envelope
71
+ * itself has no start or end, and must not be read as one segment.
60
72
  *
61
73
  * @param {function} source - factory(collector) returning { start(), stop() }
62
74
  * @param {object} buses - map of machine IDs to pubsub buses with emit()