heartbeat.js
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const logger = require('tektrans-logger');
const config = require('./config');
// const matrix = require('./matrix');
const core_url = require('./core-url');
let module_type;
function sendHeartbeat() {
if (!config || !core_url || !module_type) { return; }
let heartbeat_name = config.handler_name || config.origin;
if (config.username) {
heartbeat_name += '/' + config.username;
}
if (!heartbeat_name) {
logger.warn('Unknown heartbeat name, skip sending heartbeat');
return;
}
// const requestOptions = {
// uri: core_url + '/heartbeats',
// method: 'POST',
// json: {
// name: heartbeat_name,
// module_type: module_type,
// config: config,
// matrix: matrix
// }
// }
//request.post(requestOptions, function(err, res, body) { });
}
setInterval(
sendHeartbeat,
60 * 1000
)
function setModuleType(value) {
logger.verbose('Set heartbeat module type as ' + value + ' and starting to send heartbeat per interval');
module_type = value;
sendHeartbeat();
}
exports.setModuleType = setModuleType;