video-optimizer-bot / src /queue /watchdog.js
Hugging Face Deployer
Deploy bot to Hugging Face Spaces
03b405b
Raw History Blame Contribute Delete
683 Bytes
const { listJobs, updateJob, event } = require("./jobs");
function startWatchdog(logger) {
const interval = setInterval(() => {
const stuckCutoff = Date.now() - 90 * 60 * 1000;
for (const job of listJobs(200)) {
if (!["downloading", "compressing", "uploading"].includes(job.status)) continue;
if (Date.parse(job.updatedAt) < stuckCutoff) {
event(job.id, "warn", "Watchdog moved a stale job back to retrying");
updateJob(job.id, { status: "retrying", stage: "watchdog-retry" });
logger.warn({ jobId: job.id }, "Watchdog recovered stale job");
}
}
}, 5 * 60 * 1000);
interval.unref();
}
module.exports = { startWatchdog };