@yarkivaev/scada 1.1.5 → 1.1.6
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 +1 -1
- package/src/clickhouseSensor.js +15 -11
package/package.json
CHANGED
package/src/clickhouseSensor.js
CHANGED
|
@@ -66,17 +66,21 @@ export default function clickhouseSensor(connection, topic, displayName, unit) {
|
|
|
66
66
|
stream(since, step, callback) {
|
|
67
67
|
let lastTs = since;
|
|
68
68
|
const timer = setInterval(async () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
try {
|
|
70
|
+
const rows = await connection.query(
|
|
71
|
+
`SELECT ts, value FROM scada.metrics
|
|
72
|
+
WHERE topic = {topic:String} AND ts > {since:DateTime64(3)}
|
|
73
|
+
ORDER BY ts LIMIT 100`,
|
|
74
|
+
{ topic, since: formatDateTime(lastTs) }
|
|
75
|
+
);
|
|
76
|
+
rows.forEach((row) => {
|
|
77
|
+
const timestamp = new Date(row.ts);
|
|
78
|
+
callback({ timestamp, value: row.value, unit });
|
|
79
|
+
lastTs = timestamp;
|
|
80
|
+
});
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error('Stream query failed:', err.message); // eslint-disable-line no-console
|
|
83
|
+
}
|
|
80
84
|
}, step);
|
|
81
85
|
return {
|
|
82
86
|
cancel() {
|