You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
const { scheduleJob } = require('node-schedule');
|
|
const heytripService = require('../services/heytripService');
|
|
const { LGC_MAPPED } = require('../config/constants');
|
|
|
|
const Aids = () => {
|
|
const job = scheduleJob('*/2 * * * * *', async function () {
|
|
console.log('syncing heytrip, get available accommodation ids.');
|
|
|
|
const res = await heytripService.syncAids();
|
|
if (res.nextPage !== true) {
|
|
job.cancel();
|
|
}
|
|
});
|
|
};
|
|
|
|
const hotelLgcDetails = () => {
|
|
const job2 = scheduleJob('*/4 * * * * *', async function () {
|
|
console.log('-------------------------syncing heytrip, get accommodation details.-------------------------');
|
|
|
|
const isRunning = job2.pendingInvocations[0]?.job?.running == 1;
|
|
if (!isRunning) {
|
|
// const res = await heytripService.syncHotelDetails();
|
|
// const res = await heytripService.syncInitHotelLgcDetailsAction(LGC_MAPPED['1']);
|
|
const res = await heytripService.newHotelsLgc('1');
|
|
|
|
job2.cancel(); // debug: 0
|
|
if (res.next !== true) {
|
|
job2.cancel();
|
|
console.log('job completed! canceled job!');
|
|
}
|
|
} else {
|
|
console.log('pre job running! cancelNext');
|
|
job2.cancelNext();
|
|
}
|
|
});
|
|
};
|
|
|
|
const chinaHotelDetails = () => {
|
|
const job3 = scheduleJob('*/4 * * * * *', async function () {
|
|
console.log('syncing heytrip, get china accommodation details.');
|
|
const isRunning = job3.pendingInvocations[0]?.job?.running == 1;
|
|
if (!isRunning) {
|
|
const res = await heytripService.chinaHotelsLgc2('2');
|
|
if (res.next !== true) {
|
|
job3.cancel();
|
|
console.log('job completed! canceled job!');
|
|
// job3.reschedule('0 0 0 * * *');
|
|
}
|
|
} else {
|
|
console.log('pre job running! cancelNext');
|
|
job2.cancelNext();
|
|
}
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
Aids, hotelLgcDetails, chinaHotelDetails
|
|
}
|