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.
99 lines
3.0 KiB
JavaScript
99 lines
3.0 KiB
JavaScript
const { scheduleJob } = require('node-schedule');
|
|
const heytripService = require('../services/heytripService');
|
|
|
|
/**
|
|
* 获取可用的酒店id
|
|
*/
|
|
const Aids = () => {
|
|
return false;
|
|
// const jobA = scheduleJob('*/2 * * * * *', async function () {
|
|
const jobA = scheduleJob('0 0 0 * * *', async function () {
|
|
console.log('syncing heytrip, get available accommodation ids.');
|
|
const isRunning = jobA.pendingInvocations[0]?.job?.running == 1;
|
|
if (!isRunning) {
|
|
const res = await heytripService.syncAids();
|
|
if (res.nextPage !== true) {
|
|
console.log('job completed! canceled job!');
|
|
jobA.cancel();
|
|
}
|
|
} else {
|
|
console.log('pre job running! cancelNext');
|
|
jobA.cancelNext();
|
|
}
|
|
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 更新酒店的状态, 是否下架
|
|
*/
|
|
const AidsState = () => {
|
|
const jobAS = scheduleJob('*/2 * * * * *', async function () {
|
|
// const jobAS = scheduleJob('0 5 0 * * *', async function () {
|
|
console.log('--------------------syncing heytrip, get available accommodation ids.--------------------');
|
|
const isRunning = jobAS.pendingInvocations[0]?.job?.running == 1;
|
|
if (!isRunning) {
|
|
const res = await heytripService.syncAidState();
|
|
// jobAS.cancel(); // debug: 0
|
|
if (res.nextPage !== true) {
|
|
console.log('job completed! canceled job[AidsState]!');
|
|
jobAS.cancel();
|
|
}
|
|
} else {
|
|
console.log('pre job running! cancelNext[AidsState]');
|
|
jobAS.cancelNext();
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 更新酒店详情, 按语种
|
|
*/
|
|
const hotelLgcDetails = () => {
|
|
// return false;
|
|
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.newHotelsLgc('1');
|
|
|
|
// job2.cancel(); // debug: 0
|
|
if (res.next !== true) {
|
|
job2.cancel();
|
|
console.log('job completed! canceled job[hotelLgcDetails]!');
|
|
}
|
|
} else {
|
|
console.log('pre job running! cancelNext[hotelLgcDetails]');
|
|
job2.cancelNext();
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 更新中国酒店详情. 已完成
|
|
*/
|
|
const chinaHotelDetails = () => {
|
|
return false;
|
|
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, AidsState,
|
|
hotelLgcDetails, chinaHotelDetails
|
|
}
|