Checkpoint: Correction du scheduler : ajout des modes weekly (avec fetch_day_of_week) et monthly (avec fetch_day_of_month) dans scheduleDailyImport. Planification recette configurée : hebdomadaire, lundi à 08:00.

This commit is contained in:
Manus
2026-07-03 05:53:41 -04:00
parent 326e8b7bcf
commit b0550f3298
3 changed files with 18 additions and 7 deletions

View File

@@ -38,22 +38,33 @@ export async function scheduleDailyImport() {
const fetchMode = (await getSetting("fetch_mode")) || "scheduled";
const fetchIntervalMinutes = parseInt((await getSetting("fetch_interval_minutes")) || "1440", 10);
const fetchDayOfWeek = parseInt((await getSetting("fetch_day_of_week")) || "1", 10); // 0=dim, 1=lun, ..., 6=sam
const fetchDayOfMonth = parseInt((await getSetting("fetch_day_of_month")) || "1", 10); // 1-28
const DAYS_FR = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
let cronExpr: string;
if (fetchMode === "interval") {
const intervalMin = Math.max(60, fetchIntervalMinutes);
if (intervalMin < 60) {
cronExpr = `*/${intervalMin} * * * *`;
} else if (intervalMin % 60 === 0) {
if (intervalMin % 60 === 0) {
const hours = intervalMin / 60;
cronExpr = hours === 24 ? `0 0 * * *` : `0 */${hours} * * *`;
} else {
cronExpr = `*/${intervalMin} * * * *`;
}
console.log(`[Cron] Mode intervalle — toutes les ${intervalMin} minutes (${cronExpr})`);
} else if (fetchMode === "weekly") {
const [hour, minute] = importTime.split(":").map(Number);
cronExpr = `0 ${minute ?? 0} ${hour ?? 6} * * ${fetchDayOfWeek}`;
console.log(`[Cron] Mode hebdomadaire — chaque ${DAYS_FR[fetchDayOfWeek] ?? "lundi"} à ${importTime} (${cronExpr})`);
} else if (fetchMode === "monthly") {
const [hour, minute] = importTime.split(":").map(Number);
cronExpr = `0 ${minute ?? 0} ${hour ?? 6} ${fetchDayOfMonth} * *`;
console.log(`[Cron] Mode mensuel — le ${fetchDayOfMonth} de chaque mois à ${importTime} (${cronExpr})`);
} else {
// scheduled (heure fixe quotidienne) ou daily
const [hour, minute] = importTime.split(":").map(Number);
cronExpr = `0 ${minute ?? 0} ${hour ?? 6} * * *`;
console.log(`[Cron] Mode heure fixe — tous les jours à ${importTime} (${cronExpr})`);
console.log(`[Cron] Mode quotidien — tous les jours à ${importTime} (${cronExpr})`);
}
if (cronJob) {