@bldgblocks/node-red-contrib-control 0.1.36 → 0.1.37
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/nodes/history-buffer.js
CHANGED
|
@@ -33,7 +33,8 @@ module.exports = function(RED) {
|
|
|
33
33
|
let liveBuffer = []; // Accumulate points since last commit to BUFFER_FILE
|
|
34
34
|
let commitTimer = null;
|
|
35
35
|
let pruneTimer = null;
|
|
36
|
-
let messageCount = 0;
|
|
36
|
+
let messageCount = 0; // Total messages received
|
|
37
|
+
let activeBufferCount = 0; // Messages in current buffer file (resets on rotate)
|
|
37
38
|
let cachedChunkCount = 0; // Cached count of historical files
|
|
38
39
|
let isInitializing = true; // Flag: initialization in progress
|
|
39
40
|
let queuedMessages = []; // Queue messages during initialization
|
|
@@ -361,6 +362,7 @@ module.exports = function(RED) {
|
|
|
361
362
|
await fs.promises.access(BUFFER_FILE);
|
|
362
363
|
await fs.promises.rename(BUFFER_FILE, newName);
|
|
363
364
|
cachedChunkCount++;
|
|
365
|
+
activeBufferCount = 0; // Reset active buffer count after rotation
|
|
364
366
|
} catch (err) {
|
|
365
367
|
// BUFFER_FILE doesn't exist - no data to rotate
|
|
366
368
|
}
|
|
@@ -421,9 +423,10 @@ module.exports = function(RED) {
|
|
|
421
423
|
});
|
|
422
424
|
|
|
423
425
|
messageCount++;
|
|
426
|
+
activeBufferCount++; // Increment count of messages in current buffer file
|
|
424
427
|
|
|
425
428
|
// Status update (throttled internally to 1s)
|
|
426
|
-
updateStatus(`${messageCount}
|
|
429
|
+
updateStatus(`${messageCount} processed, ${activeBufferCount} active, ${cachedChunkCount} chunks`, messageCount === 1);
|
|
427
430
|
|
|
428
431
|
if (done) done();
|
|
429
432
|
});
|
|
@@ -106,6 +106,15 @@ module.exports = function(RED) {
|
|
|
106
106
|
// Set initial status
|
|
107
107
|
utils.setStatusOK(node, "configuration received");
|
|
108
108
|
|
|
109
|
+
// Emit event for history-service relay (InfluxDB batch format)
|
|
110
|
+
const eventName = `bldgblocks:history:${node.historyConfig.id}`;
|
|
111
|
+
RED.events.emit(eventName, {
|
|
112
|
+
measurement: escapedMeasurementName,
|
|
113
|
+
fields: { value: formattedValue },
|
|
114
|
+
tags: tagsObj,
|
|
115
|
+
timestamp: timestamp
|
|
116
|
+
});
|
|
117
|
+
|
|
109
118
|
// Handle storage type
|
|
110
119
|
if (node.storageType === 'memory') {
|
|
111
120
|
const contextKey = `history_data_${node.historyConfig.name}`;
|
package/nodes/history-service.js
CHANGED
|
@@ -15,6 +15,18 @@ module.exports = function(RED) {
|
|
|
15
15
|
// Generate matching event name based on history-config ID
|
|
16
16
|
const eventName = `bldgblocks:history:${node.historyConfig.id}`;
|
|
17
17
|
|
|
18
|
+
// Status throttling - prevent rapid status updates from fast-streaming histories
|
|
19
|
+
let lastRelayedName = null;
|
|
20
|
+
let statusDirty = false;
|
|
21
|
+
let statusInterval = null;
|
|
22
|
+
|
|
23
|
+
statusInterval = setInterval(() => {
|
|
24
|
+
if (statusDirty && lastRelayedName) {
|
|
25
|
+
utils.setStatusChanged(node, `relayed: ${lastRelayedName}`);
|
|
26
|
+
statusDirty = false;
|
|
27
|
+
}
|
|
28
|
+
}, 2000);
|
|
29
|
+
|
|
18
30
|
// Listen for events from history-collector nodes with this config
|
|
19
31
|
const eventListener = (eventData) => {
|
|
20
32
|
// Guard against invalid event data
|
|
@@ -24,17 +36,14 @@ module.exports = function(RED) {
|
|
|
24
36
|
return;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
//
|
|
28
|
-
// Preserve topic if it exists in the event data
|
|
39
|
+
// Send event data directly as payload (already in InfluxDB batch format)
|
|
29
40
|
const msg = {
|
|
30
|
-
payload: eventData
|
|
31
|
-
topic: eventData.topic
|
|
41
|
+
payload: eventData
|
|
32
42
|
};
|
|
33
43
|
|
|
34
44
|
node.send(msg);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
utils.setStatusChanged(node, `relayed: ${eventData.seriesName || 'data'}`);
|
|
45
|
+
lastRelayedName = eventData.measurement || 'data';
|
|
46
|
+
statusDirty = true;
|
|
38
47
|
};
|
|
39
48
|
|
|
40
49
|
// Subscribe to events
|
|
@@ -42,6 +51,11 @@ module.exports = function(RED) {
|
|
|
42
51
|
utils.setStatusOK(node, `listening on ${node.historyConfig.name}`);
|
|
43
52
|
|
|
44
53
|
node.on("close", function(done) {
|
|
54
|
+
// Clear status interval
|
|
55
|
+
if (statusInterval) {
|
|
56
|
+
clearInterval(statusInterval);
|
|
57
|
+
statusInterval = null;
|
|
58
|
+
}
|
|
45
59
|
// Unsubscribe from events on close
|
|
46
60
|
RED.events.off(eventName, eventListener);
|
|
47
61
|
done();
|
package/package.json
CHANGED