-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (39 loc) · 1.17 KB
/
app.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
38
39
40
41
42
43
44
45
46
const { exec } = require("child_process");
const knex = require("knex")(require("./knexfile"));
const cron = require('node-cron');
require('dotenv').config();
const runSpeedTest = () => {
return new Promise(resolve => {
exec("speedtest -f json", (error, stdout, stderr) => {
if (error) {
console.log("Fehler beim Aufrufen des Speedtests!");
resolve(false);
return;
}
if (stderr) {
console.log("Fehler beim Aufrufen des Speedtests!");
resolve(false);
return;
}
resolve(stdout);
});
});
}
const main = async () => {
const result = await runSpeedTest();
if (result != false) {
const json = JSON.parse(result);
await knex("results").insert({
latency: json.ping.latency,
jitter: json.ping.jitter,
download: json.download.bandwidth,
upload: json.upload.bandwidth,
packetLoss: json.packetLoss,
host: json.server.name
});
return;
}
};
cron.schedule(process.env.INTERVAL, async () => {
await main();
});