Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

fix(scheduler): prune notifications and AI usage once a day at 03:00 instead of every hourly automation tick

Khuram Niaz24e7baff5e0f
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 2a34950..e231f70 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -271,6 +271,7 @@ export const APP_CONSTANTS = {
export const SCHEDULER_CONSTANTS = {
ENABLED: true,
CRON_EXPRESSION: "0 * * * *", // Every hour at minute 0
+ PRUNE_CRON_EXPRESSION: "0 3 * * *", // Daily at 03:00; reads filter anyway
STALE_RUN_TIMEOUT_MS: 15 * 60 * 1000, // 15 min; reaper cutoff for stuck runs
} as const;
diff --git a/src/lib/scheduler/index.ts b/src/lib/scheduler/index.ts
index b39e797..59c528f 100644
--- a/src/lib/scheduler/index.ts
+++ b/src/lib/scheduler/index.ts
@@ -8,6 +8,14 @@ import { pruneNotifications } from "@/lib/notifications/prune";
import { pruneAiCalls } from "@/lib/aiUsage/prune";
let scheduledTask: ScheduledTask | null = null;
+let pruneTask: ScheduledTask | null = null;
+
+// Both prunes log and swallow their own errors.
+async function runPrunes() {
+ const now = new Date();
+ await pruneNotifications(now);
+ await pruneAiCalls(now);
+}
async function runDueAutomations() {
const now = new Date();
@@ -16,8 +24,6 @@ async function runDueAutomations() {
});
try {
- await pruneNotifications(now);
- await pruneAiCalls(now);
const dueAutomations = await db.automation.findMany({
where: {
status: "active",
@@ -150,6 +156,11 @@ export function startScheduler() {
scheduledTask = cron.schedule(cronExpression, runDueAutomations, {
timezone: process.env.TZ || "UTC",
});
+ pruneTask = cron.schedule(
+ SCHEDULER_CONSTANTS.PRUNE_CRON_EXPRESSION,
+ runPrunes,
+ { timezone: process.env.TZ || "UTC" },
+ );
log.info("[Scheduler] Started successfully");
}
@@ -158,6 +169,8 @@ export function stopScheduler() {
if (scheduledTask) {
scheduledTask.stop();
scheduledTask = null;
+ pruneTask?.stop();
+ pruneTask = null;
log.info("[Scheduler] Stopped");
}
}