Checkpoint: Ajout de la prochaine date d'exécution dynamique dans les Paramètres (calcul frontend selon mode/heure/jour, aligné sur le cron réel backend). Ajout de la règle de rétention configurable (Illimité/3/6/12/18/24 mois) avec purge automatique au démarrage et après chaque import. 0 erreur TypeScript, 21 tests passés.
This commit is contained in:
@@ -12,7 +12,7 @@ import { runFullImport } from "../importer";
|
||||
import uploadRoutes from "../uploadRoutes";
|
||||
import scheduledRoutes from "../scheduledRoutes";
|
||||
import { ensureAdminExists } from "../localAuth";
|
||||
import { getSetting } from "../db";
|
||||
import { getSetting, purgeOldArticles } from "../db";
|
||||
import { runRssFetch } from "../rssEngine";
|
||||
|
||||
function isPortAvailable(port: number): Promise<boolean> {
|
||||
@@ -91,6 +91,19 @@ export async function scheduleDailyImport() {
|
||||
} catch (e) {
|
||||
console.error("[Cron] Erreur lors de la lecture RSS:", e);
|
||||
}
|
||||
// 3. Purge des articles selon la règle de rétention
|
||||
try {
|
||||
const retentionStr = await getSetting("retention_months");
|
||||
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
||||
if (retentionMonths > 0) {
|
||||
const purged = await purgeOldArticles(retentionMonths);
|
||||
if (purged.veille > 0 || purged.aap > 0) {
|
||||
console.log(`[Cron] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[Cron] Erreur lors de la purge de rétention:", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,6 +149,15 @@ async function startServer() {
|
||||
try {
|
||||
await ensureAdminExists();
|
||||
await scheduleDailyImport();
|
||||
// Purge de rétention au démarrage
|
||||
const retentionStr = await getSetting("retention_months");
|
||||
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
||||
if (retentionMonths > 0) {
|
||||
const purged = await purgeOldArticles(retentionMonths);
|
||||
if (purged.veille > 0 || purged.aap > 0) {
|
||||
console.log(`[Init] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[Init] Erreur d'initialisation:", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user