@yarkivaev/scada 1.1.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "SCADA domain objects for plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
- const rows = await connection.query(
70
- `SELECT ts, value FROM scada.metrics
71
- WHERE topic = {topic:String} AND ts > {since:DateTime64(3)}
72
- ORDER BY ts LIMIT 100`,
73
- { topic, since: formatDateTime(lastTs) }
74
- );
75
- rows.forEach((row) => {
76
- const timestamp = new Date(row.ts);
77
- callback({ timestamp, value: row.value, unit });
78
- lastTs = timestamp;
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() {