-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.js
29 lines (26 loc) · 895 Bytes
/
cron.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
// Cron job to hit endpoint every 14 sec to keep backend alive always
const cron = require('cron');
const https = require('https');
const backendUrl = 'https://synthome-fyi.onrender.com/papers';
const job = new cron.CronJob('*/14 * * * * *', function () {
// This function will be executed every 14 seconds
console.log('Restarting server');
// Perform an HTTPS GET request to hit any backend api.
https
.get(backendUrl, (res) => {
if (res.statusCode == 200) {
console.log('Server restarted');
} else {
console.error(
`Failed to restart server with status code: ${res.statusCode}`
);
}
})
.on('error', (err) => {
console.error('Error During Restart:', err.message);
});
});
// Export the cron job.
module.exports = {
job,
};