feat: allow quiet cronjobs (#1696)

Co-authored-by: zk <--global>
This commit is contained in:
zk
2026-06-19 17:38:38 +01:00
committed by GitHub
co-authored by zk
parent 762d6398a3
commit a61bb7510c
3 changed files with 15 additions and 6 deletions
@@ -22,6 +22,12 @@ export interface CronTaskDef {
schedule: string;
/** Shown in admin and synced to `cron_task.description`. */
description: string;
/**
* When true, the scheduler logs completion at debug instead of info, and the task's own
* routine logs should also be at debug. Use for high-frequency tasks whose output is too
* noisy at info level.
*/
quiet?: boolean;
run: () => Promise<void>;
}
@@ -59,6 +65,7 @@ function buildList(): Array<CronTaskDef> {
schedule: "* * * * *", // TODO(zk): really? this is so lazy
description:
"Drain score_rederive, pb_dirty, session_dirty, game_profile_dirty (ordered)",
quiet: true,
run: drainStatsQueuesInOrder,
},
];
@@ -158,7 +158,9 @@ export async function runCronTickOnce(): Promise<void> {
})
.where("cron_task_execution.id", "=", execRow.id)
.execute();
log.info(`Cron task ${def.id} completed for fire ${scheduledAtIso}.`);
(def.quiet ? log.debug : log.info)(
`Cron task ${def.id} completed for fire ${scheduledAtIso}.`,
);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
log.error({ err }, `Cron task ${def.id} failed.`);
@@ -80,7 +80,7 @@ export async function drainPbDirty(): Promise<number> {
});
}
log.info(`Drained ${rows.length} pb_dirty entries across ${groups.size} user/game groups.`);
log.debug(`Drained ${rows.length} pb_dirty entries across ${groups.size} user/game groups.`);
return rows.length;
}
@@ -186,7 +186,7 @@ export async function drainSessionDirty(): Promise<number> {
.execute();
}
log.info(`Drained ${rows.length} session_dirty entries.`);
log.debug(`Drained ${rows.length} session_dirty entries.`);
return rows.length;
}
@@ -211,7 +211,7 @@ export async function drainGameProfileDirty(): Promise<number> {
});
}
log.info(`Drained ${rows.length} game_profile_dirty entries.`);
log.debug(`Drained ${rows.length} game_profile_dirty entries.`);
return rows.length;
}
@@ -254,7 +254,7 @@ export async function drainStatsQueuesInOrder(): Promise<void> {
.executeTakeFirst(),
]);
log.info(
log.debug(
{
score_rederive: Number(queueSizes[0]?.n ?? 0),
pb_dirty: Number(queueSizes[1]?.n ?? 0),
@@ -330,7 +330,7 @@ export async function drainStatsQueuesInOrder(): Promise<void> {
const elapsedMs = Date.now() - tickStart;
log.info({ elapsedMs }, "drainStatsQueuesInOrder: tick complete");
log.debug({ elapsedMs }, "drainStatsQueuesInOrder: tick complete");
}
/**