Skip to content

Commit 484e4e7

Browse files
committed
[bmd-videohub] handle missing 'ALARM STATUS' on some models
1 parent fe9c306 commit 484e4e7

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

src/modules/bmd-videohub/container/workers/worker-videohub.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const videohub = require("@utils/videohub-promise");
1212
const updateDelay = 2000;
1313
let dataCollection;
1414
let lastSeen = null;
15+
const disabledStatusFields = new Set();
1516

1617
// Tell the manager the things you care about
1718
parentPort.postMessage({
@@ -47,6 +48,33 @@ const saveResult = async (newResults) => {
4748
}
4849
};
4950

51+
const queryStatusFields = async (router, fields) => {
52+
const results = [];
53+
54+
for (const field of fields) {
55+
if (disabledStatusFields.has(field)) {
56+
continue;
57+
}
58+
59+
try {
60+
const result = await router.query(field);
61+
if (result) {
62+
results.push(result);
63+
lastSeen = Date.now();
64+
}
65+
} catch (error) {
66+
logger.warning(`Poll field error (${field}): ${error.message}`);
67+
68+
// Some devices do not implement all fields (e.g. ALARM STATUS).
69+
// Disable field after first failure to avoid repeated timeout noise.
70+
disabledStatusFields.add(field);
71+
logger.info(`Disabling unsupported poll field: ${field}`);
72+
}
73+
}
74+
75+
return results;
76+
};
77+
5078
const main = async () => {
5179
// Connect to the db
5280
await mongoDb.connect(workerData.id);
@@ -88,11 +116,18 @@ const main = async () => {
88116

89117
while (true) {
90118
try {
91-
// Query all status fields in batch
92-
const results = await router.queryBatch(statusDumpFields);
93-
94-
// Save all results
95-
await saveResult(results);
119+
// Query all status fields with per-field fault tolerance
120+
const results = await queryStatusFields(router, statusDumpFields);
121+
122+
// Save any successful responses and continue polling
123+
if (results.length > 0) {
124+
await saveResult(results);
125+
} else {
126+
logger.warning("Poll returned no status blocks");
127+
if (!lastSeen || Date.now() - lastSeen > 1000 * 30) {
128+
throw new Error("No response from device in 30 seconds");
129+
}
130+
}
96131

97132
// Poll periodically
98133
await delay(updateDelay);

0 commit comments

Comments
 (0)