-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (42 loc) · 1.18 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require('dotenv').config();
const express = require('express');
const cron = require('node-cron');
const fetch = require('node-fetch');
const {setIntervalAsync} = require('set-interval-async/dynamic');
const checkHeb = require('./crawlers/heb');
const checkAlamodome = require('./crawlers/alamodome');
const checkUniversity = require('./crawlers/university');
const checkWalmart = require('./crawlers/walmart');
const checkWalgreens = require('./crawlers/walgreens');
const checkCvs = require('./crawlers/cvs');
const cronJobInterval = '*/1 * * * *';
app = express();
const keepaliveURL = process.env.KEEP_ALIVE_URL;
app.get('/alive', function(req, res) {
res.send('Staying alive.');
});
cron.schedule(cronJobInterval, async () => {
try {
const keep = await fetch(keepaliveURL);
const alive = await keep.text();
console.log(alive);
await checkAlamodome();
await checkUniversity();
await checkWalmart();
await checkWalgreens();
await checkCvs();
} catch (error) {
console.error(error);
}
});
try {
setIntervalAsync(
async () => {
await checkHeb();
},
1000 * 5,
);
} catch (e) {
console.error(e);
}
app.listen(process.env.PORT);