-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (27 loc) · 1017 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (27 loc) · 1017 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
25
26
27
28
29
30
31
32
const cron = require('node-cron')
const scrap = require('./scrap')
const { getBookedDateList, setCache, enableService, getFilteredBookedList } = require('./utils')
/* Start scrapping process */
const init = async () => {
const bookedDateList = await getBookedDateList()
if ([0, 1].includes(bookedDateList.length)) scrap()
}
/* Discard old booking based on current date */
const discardOldBookings = async () => {
const bookedDateList = await getBookedDateList()
const updatedCache = { list: getFilteredBookedList(bookedDateList) }
setCache('BOOKED_DATES', updatedCache)
}
if (enableService) {
console.log(`Scrapping initiated at ${new Date()}`)
/* Cron set for every 1 hour to start the process */
cron.schedule('0 * * * *', () => {
console.log(`Scraping initiated at ${new Date()}`)
init()
})
/* Cron set for every 6 hours to discard old dates */
cron.schedule('0 */6 * * *', () => {
console.log(`Discard old dates initiated at ${new Date()}`)
discardOldBookings()
})
}