const cron = require('node-cron'); /** * Initializes all backend cron jobs. */ const initCronJobs = () => { const schedule = '*/30 * * * *'; // Default to every 30 minutes const targetUrl = "https://aliroohan179-face.hf.space/api/health"; if (!targetUrl) { console.log('ℹ️ Cron Service: No CRON_TARGET_URL configured. Cron job is idle.'); return; } console.log(`⏰ Cron Service: Scheduled job with pattern "${schedule}" to call URL: ${targetUrl}`); cron.schedule(schedule, async () => { console.log(`⏰ Cron Service: Executing scheduled job at ${new Date().toISOString()}`); try { const response = await fetch(targetUrl); console.log(`✅ Cron Service: API call to ${targetUrl} succeeded with status ${response.status}`); } catch (error) { console.error(`❌ Cron Service: API call to ${targetUrl} failed. Error:`, error.message); } }); }; module.exports = { initCronJobs };