feat: worker in-process de refresh périodique (croner)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
// server/jobs/worker.ts
|
||||||
|
import { Cron } from "croner";
|
||||||
|
import { listMachines } from "../services/machines.js";
|
||||||
|
import { refreshMachine } from "../services/refresh.js";
|
||||||
|
|
||||||
|
let job: Cron | null = null;
|
||||||
|
|
||||||
|
/** Rafraîchit toutes les machines toutes les 30 minutes (tâche de fond). */
|
||||||
|
export function startWorker(): void {
|
||||||
|
job = new Cron("*/30 * * * *", async () => {
|
||||||
|
for (const m of listMachines()) {
|
||||||
|
try {
|
||||||
|
await refreshMachine(m.id);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[worker] refresh échoué pour ${m.id}:`, (err as Error).message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stopWorker(): void {
|
||||||
|
job?.stop();
|
||||||
|
job = null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user