-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import dotenv from "dotenv"; | ||
import got from "got"; | ||
import * as Sentry from "@sentry/node"; | ||
import { pathTo } from "#utils/path.js"; | ||
|
||
dotenv.config({ path: pathTo(import.meta.url, "../.env") }); | ||
|
||
const UPTIME_MONITOR_URL = process.env.UPTIME_MONITOR_URL; | ||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function run(url) { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set("msg", "OK"); | ||
searchParams.set("ping", "0"); | ||
searchParams.set("status", "up"); | ||
|
||
await got.post(url + "?" + searchParams.toString()); | ||
} | ||
|
||
for (;;) { | ||
// Don't start the uptime service if the monitor url is empty. | ||
if (!UPTIME_MONITOR_URL) { | ||
break; | ||
} | ||
|
||
let done = false; | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await run(UPTIME_MONITOR_URL) | ||
.catch((error) => { | ||
Sentry.captureException(error); | ||
}) | ||
.finally(() => { | ||
done = true; | ||
}); | ||
|
||
while (!done) { | ||
// wait | ||
await sleep(1000); | ||
Check warning on line 42 in src/uptime.js GitHub Actions / Check
|
||
} | ||
|
||
// How long do we need to sleep | ||
const now = new Date(); | ||
const nextTime = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes() + 1, now.getUTCSeconds(), 0); | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await sleep(nextTime.getTime() - now.getTime()); | ||
} |