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)
19 lines
923 B
TypeScript
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);
|
|
}
|