File size: 944 Bytes
aa535fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 };