Node.js
Node.js 18 and later have fetch built in.
const URL = "https://staging.crony.sh/ping/f3a1c6e2-8d4b-4c7a-9e15-2b6d0c9a7f31";
async function ping(suffix = "", body) {
try {
await fetch(URL + suffix, {
method: body === undefined ? "GET" : "POST",
body,
signal: AbortSignal.timeout(10_000),
});
} catch (error) {
// A failed ping must not stop the job.
console.error("Ping failed:", error);
}
}
await ping("/start");
try {
await runBackup();
await ping();
} catch (error) {
await ping("/fail", String(error).slice(0, 10_000));
throw error;
}