forked from coderonfleek/simple-node-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.js
More file actions
24 lines (22 loc) · 819 Bytes
/
cron.js
File metadata and controls
24 lines (22 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var CronJob = require('cron').CronJob;
let porta = process.env.PORT || 80;
const { default: axios } = require('axios');
var express = require('express');
const http = require(`http`);
const app = express();
app.get(`/health`, (req, res) => res.status(200).json(`OK`));
const server = http.createServer(app);
server.listen(
porta,
() => console.log(`-- Backend Service (${porta}) --`)
);
const job = new CronJob('0 */1 * * * *', async function () {
try {
let response = await axios.get(process.env.CLIENT_URL)//configurar o CLIENT_URL=https://something/health
console.log('Resposta so servidor: OK', JSON.stringify(response.data))
} catch (error) {
console.log('ocorreu um erro:', JSON.stringify(error))
}
});
console.log('Resposta do servidor a cada minuto');
job.start();