Commit 714f147ac5c4270276eb3ad08691b3afe33732d3

Authored by Adhidarma Hadiwinoto
1 parent b3b28d49f7
Exists in master

MODEM-INFO: logs on idle check

Showing 1 changed file with 3 additions and 2 deletions Inline Diff

1 const DEFAULT_MAX_LAST_DATA_AGE_MS = 2 * 60 * 1000; 1 const DEFAULT_MAX_LAST_DATA_AGE_MS = 2 * 60 * 1000;
2 const DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS = 30 * 1000; 2 const DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS = 30 * 1000;
3 3
4 const config = require('komodo-sdk/config'); 4 const config = require('komodo-sdk/config');
5 const logger = require('komodo-sdk/logger'); 5 const logger = require('komodo-sdk/logger');
6 6
7 const modemInfo = { 7 const modemInfo = {
8 device: config.modem.device, 8 device: config.modem.device,
9 manufacturer: null, 9 manufacturer: null,
10 model: null, 10 model: null,
11 imei: null, 11 imei: null,
12 imsi: null, 12 imsi: null,
13 cops: null, 13 cops: null,
14 networkId: null, 14 networkId: null,
15 networkName: null, 15 networkName: null,
16 signalStrength: null, 16 signalStrength: null,
17 signalStrengthTs: null, 17 signalStrengthTs: null,
18 signalStrengthTsReadable: null, 18 signalStrengthTsReadable: null,
19 startTime: new Date(), 19 startTime: new Date(),
20 lastWriteTs: null, 20 lastWriteTs: null,
21 lastReadTs: null, 21 lastReadTs: null,
22 }; 22 };
23 23
24 if (!config.disable_idle_check) { 24 if (!config.disable_idle_check) {
25 setInterval(() => { 25 setInterval(() => {
26 const deltaMs = new Date() - Math.max( 26 const deltaMs = new Date() - Math.max(
27 modemInfo.startTime, 27 modemInfo.startTime,
28 Math.min(modemInfo.lastWriteTs, modemInfo.lastReadTs), 28 Math.min(modemInfo.lastWriteTs, modemInfo.lastReadTs),
29 ); 29 );
30 30
31 if (deltaMs >= (config.max_last_data_age_ms || DEFAULT_MAX_LAST_DATA_AGE_MS)) { 31 const maxLastDataAgeMs = config.max_last_data_age_ms || DEFAULT_MAX_LAST_DATA_AGE_MS;
32 logger.warn(`Modem idle for ${deltaMs} ms. Modem stucked? Terminating!`); 32 if (deltaMs >= maxLastDataAgeMs) {
33 logger.warn(`Modem idle for more than ${maxLastDataAgeMs} ms. Stucked modem? Terminating!`, { deltaMs });
33 process.exit(1); 34 process.exit(1);
34 } 35 }
35 }, config.interval_beetwen_signal_strength_ms || DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS); 36 }, config.interval_beetwen_signal_strength_ms || DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS);
36 } 37 }
37 38
38 module.exports = modemInfo; 39 module.exports = modemInfo;
39 40