-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.js
31 lines (28 loc) · 811 Bytes
/
healthcheck.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
var axios = require('axios');
function ReportHealthCheckStatus(key, status , message ) {
let healthCheckUrl = process.env["HEALTH_CHECK_URL_"+key];
if (healthCheckUrl && healthCheckUrl.length) {
ReportStatus(healthCheckUrl, status, message)
}
}
// Never throws
async function ReportStatus(joburl, status, message){
if(message && message.length){
try{
await axios.post(`${joburl}/${status}`, {
message: message
})
} catch (err){
console.log("Error reporting health check status: ", err);
}
}else{
try{
await axios.get(`${joburl}/${status}`)
} catch(err){
console.log("Error reporting health check status: ", err);
}
}
}
module.exports = {
ReportHealthCheckStatus
}