-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
40 lines (32 loc) · 884 Bytes
/
index.mjs
File metadata and controls
40 lines (32 loc) · 884 Bytes
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
import 'dotenv/config';
import fetch from 'node-fetch';
import ping from 'ping';
import { CronJob } from 'cron';
new CronJob(
'*/30 * * * * *',
pushStatus,
null,
true,
process.env.TZ
)
if (!process.env.URL) {
console.error("URL not set");
process.exit(1);
}
console.info("Started push job");
async function pushStatus() {
try {
const address = process.env.URL.split('/')[2];
const { output, time } = await ping.promise.probe(address);
if (time === 'unknown')
throw new Error(output.split(':')[1].trim());
const response = await fetch(process.env.URL + '?status=up&msg=OK&ping=' + Math.round(time));
const data = await response.json();
if (!data.ok)
throw new Error(data.msg);
}
catch (e) {
console.error("Check failed: " + e.message);
}
}
pushStatus();