24 lines
753 B
TypeScript
24 lines
753 B
TypeScript
import { generateDailyHoroscopes } from "./horoscope-generator";
|
|
|
|
async function runDailyGeneration() {
|
|
try {
|
|
await generateDailyHoroscopes();
|
|
} catch (err: any) {
|
|
console.error("[scheduler] Horoscope generation failed:", err.message);
|
|
}
|
|
}
|
|
|
|
export function startDailyScheduler() {
|
|
// Run once at startup (generators are idempotent — they skip if today already exists).
|
|
runDailyGeneration();
|
|
|
|
// Re-check every 6 hours. Covers the day rollover without relying on container restarts.
|
|
const SIX_HOURS = 6 * 60 * 60 * 1000;
|
|
setInterval(() => {
|
|
console.log("[scheduler] Running scheduled daily generation check...");
|
|
runDailyGeneration();
|
|
}, SIX_HOURS);
|
|
|
|
console.log("[scheduler] Daily horoscope scheduler started.");
|
|
}
|