-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 920 Bytes
/
index.js
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
30
31
32
33
34
35
36
import cron from 'node-cron';
import fetch from 'node-fetch';
import dotenv from 'dotenv';
dotenv.config();
const BASE_URL = 'https://track-hub.vercel.app/api';
const CRON_SECRET = process.env.CRON_SECRET;
if(!CRON_SECRET) {
throw new Error('CRON_SECRET is required');
}
async function hourlyNotification() {
try {
const response = await fetch(`${BASE_URL}/notifyHourly`, {
method: 'GET',
headers: {
Authorization: `Bearer ${CRON_SECRET}`,
'Content-Type': 'application/json',
}
});
if(!response.ok) {
throw new Error('Failed to send hourly notification');
}
console.log(`Hourly notification sent at ${new Date().toISOString()}`);
} catch (error) {
console.error('Failed to send hourly notification');
}
}
cron.schedule('30 * * * *', () => {
hourlyNotification();
});