-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathscheduler.js
29 lines (23 loc) · 1010 Bytes
/
scheduler.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
const talenta = require("./index");
const cron = require("node-cron");
const { cookiesTalenta, longitude, latitude, timeClockIn, timeClockOut } = require("./config");
const parseTime = (time) => {
return time.split(":");
};
const scheduler = async (time, callback) => {
const [hour, min] = parseTime(time);
const task = cron.schedule(`${min} ${hour} * * 1-5`, async () => {
console.log(await callback());
});
return task;
};
(async () => {
if (timeClockIn && timeClockOut) {
console.log(`Start scheduler for your clockIn every ${timeClockIn} and clockOut every ${timeClockOut}`);
await scheduler(timeClockIn, () => talenta.clockIn({ lat: latitude, long: longitude, cookies: cookiesTalenta, desc: "Hello I am In" }));
await scheduler(timeClockOut, () => talenta.clockOut({ lat: latitude, long: longitude, cookies: cookiesTalenta, desc: "Goodbye I am Out" }));
} else {
console.error("✖︎ Error: timeClockIn and timeClockOut undefined");
process.exit(1);
}
})();