forked from ptarmiganlabs/butler-cw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheartbeat.js
37 lines (32 loc) · 1.04 KB
/
heartbeat.js
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
var later = require('later');
const axios = require('axios');
var callRemoteURL = function (remoteURL) {
axios
.get(remoteURL)
.then(function (response) {
// handle success
logger.debug(`HEARTBEAT: Sent heartbeat to ${remoteURL}`);
})
.catch(function (error) {
// handle error
logger.error(`HEARTBEAT: Error sending heartbeat: ${error}`);
});
};
function setupHeartbeatTimer(config, logger) {
try {
logger.debug(
`HEARTBEAT: Setting up heartbeat to remote: ${config.get('heartbeat.remoteURL')}`,
);
var sched = later.parse.text(config.get('heartbeat.frequency'));
var t = later.setInterval(function () {
callRemoteURL(config.get('heartbeat.remoteURL'));
}, sched);
// Do an initial ping to the remote URL
callRemoteURL(config.get('heartbeat.remoteURL'));
} catch (err) {
logger.error(`HEARTBEAT: Error ${err}`);
}
}
module.exports = {
setupHeartbeatTimer,
};