schedule.js
808 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
33
34
35
36
37
38
39
40
const schedule = require('node-schedule')
const checkin = require('./checkin')
const checkout = require('./checkout')
function sleep(ms) {
return new Promise(function(resolve) {
setTimeout(() => {
resolve()
}, ms)
})
}
const TEN_MINUTES = 10 * 60 * 1000
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function main() {
const ruleIn = new schedule.RecurrenceRule()
ruleIn.hour = 8
ruleIn.minute = 55
schedule.scheduleJob(ruleIn, function(){
sleep(getRandomInt(TEN_MINUTES)).then(checkin)
});
const ruleOut = new schedule.RecurrenceRule()
ruleOut.hour = 18
schedule.scheduleJob(ruleOut, function(){
sleep(getRandomInt(TEN_MINUTES)).then(checkout)
});
console.log('schedule start')
}
module.exports = {
start: main
}