Files
mailflare/server/runtime/scheduler.ts
T
midego 2b7d78bac7 Auto-delete Trash and Spam after a chosen number of days
Adds Settings > Inbox > Trash and Spam clean-up (closes #68, part 2).

- users.trash_retention_days (null = never) via GET/PATCH /api/settings/trash-retention
- messages.trashed_at, kept current by triggers whichever code path changes status
- Scheduled maintenance purges expired messages in batches of 200 (Workers cron and Node scheduler)
2026-10-05 10:48:51 +07:00

19 lines
923 B
TypeScript

import { runScheduledDatabaseBackup } from "@/lib/backups/runner";
import { runAgentMaintenance } from "@/lib/agent/maintenance";
import { runTrashRetention } from "@/lib/email/trash-retention";
/** Fire the daily 02:00 UTC backup and the recurring maintenance jobs, matching the cron triggers in wrangler.jsonc. */
export function startScheduler(env: CloudflareEnv) {
let lastRunDay = "";
const timer = setInterval(() => {
runAgentMaintenance(env).catch((error) => console.error("Agent maintenance failed", error));
runTrashRetention(env).catch((error) => console.error("Trash retention failed", error));
const now = new Date();
const day = now.toISOString().slice(0, 10);
if (now.getUTCHours() !== 2 || lastRunDay === day) return;
lastRunDay = day;
runScheduledDatabaseBackup(env, now).catch((error) => console.error("Scheduled backup failed", error));
}, 60_000);
return () => clearInterval(timer);
}