conf: 同步触发规则
parent
997e9adbeb
commit
773ef97a27
@ -1,98 +1,151 @@
|
||||
const { scheduleJob } = require('node-schedule');
|
||||
const heytripService = require('../services/heytripService');
|
||||
|
||||
/**
|
||||
* node-schedule
|
||||
* ? * * * * * *
|
||||
┬ ┬ ┬ ┬ ┬ ┬
|
||||
│ │ │ │ │ │
|
||||
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
|
||||
│ │ │ │ └───── month (1 - 12)
|
||||
│ │ │ └────────── day of month (1 - 31)
|
||||
│ │ └─────────────── hour (0 - 23)
|
||||
│ └──────────────────── minute (0 - 59)
|
||||
└───────────────────────── second (0 - 59, OPTIONAL)
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取可用的酒店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 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();
|
||||
// }
|
||||
|
||||
});
|
||||
// });
|
||||
};
|
||||
|
||||
/**
|
||||
* 更新酒店的状态, 是否下架
|
||||
* 每天启动同步;
|
||||
* * 每次同步需要3000+页
|
||||
*/
|
||||
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();
|
||||
const dailyJob = scheduleJob('0 0 0 * * *', async function () {
|
||||
const jobAS = scheduleJob('*/2 * * * * *', 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();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取新增的酒店详情
|
||||
* ID同步结束后启动, ID大约需要3小时
|
||||
* 每天03:05:00启动
|
||||
*/
|
||||
const newHotelDetails = () => {
|
||||
// return false;
|
||||
const dailyJob1 = scheduleJob('0 5 3 * * *', async function () {
|
||||
const job1 = scheduleJob('*/5 * * * * *', async function () {
|
||||
console.log('-------------------------syncing heytrip, get accommodation details.-------------------------');
|
||||
|
||||
const isRunning = job1.pendingInvocations[0]?.job?.running == 1;
|
||||
if (!isRunning) {
|
||||
const res = await heytripService.newHotels('1');
|
||||
|
||||
// job1.cancel(); // debug: 0
|
||||
if (res.next !== true) {
|
||||
job1.cancel(res.restart);
|
||||
console.log('job completed! canceled job[newHotelDetails]!');
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext[newHotelDetails]');
|
||||
job1.cancelNext();
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext[AidsState]');
|
||||
jobAS.cancelNext();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 更新酒店详情, 按语种
|
||||
* 每周启动一次
|
||||
* 周五20:05:00启动
|
||||
*/
|
||||
const hotelLgcDetails = () => {
|
||||
// return false;
|
||||
const job2 = scheduleJob('*/4 * * * * *', async function () {
|
||||
console.log('-------------------------syncing heytrip, get accommodation details.-------------------------');
|
||||
const dailyJob2 = scheduleJob('0 5 20 * * 5', async function () {
|
||||
const job2 = scheduleJob('*/5 * * * * *', 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');
|
||||
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]!');
|
||||
// job2.cancel(); // debug: 0
|
||||
if (res.next !== true) {
|
||||
job2.cancel(res.restart);
|
||||
console.log('job completed! canceled job[hotelLgcDetails]!');
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext[hotelLgcDetails]');
|
||||
job2.cancelNext();
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext[hotelLgcDetails]');
|
||||
job2.cancelNext();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 更新中国酒店详情. 已完成
|
||||
* 更新中国酒店的中文详情.
|
||||
* 每周启动一次
|
||||
* 周六20:05:00启动
|
||||
*/
|
||||
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 * * *');
|
||||
// return false;
|
||||
const dailyJobCN = scheduleJob('0 5 20 * * 6', async function () {
|
||||
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');
|
||||
// job3.cancel(); // debug: 0
|
||||
if (res.next !== true) {
|
||||
job3.cancel(res.restart);
|
||||
console.log('job completed! canceled job[chinaHotelDetails]!');
|
||||
// job3.reschedule('0 0 0 * * *');
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext');
|
||||
job3.cancelNext();
|
||||
}
|
||||
} else {
|
||||
console.log('pre job running! cancelNext');
|
||||
job2.cancelNext();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Aids, AidsState,
|
||||
hotelLgcDetails, chinaHotelDetails
|
||||
newHotelDetails, hotelLgcDetails, chinaHotelDetails
|
||||
}
|
||||
|
Loading…
Reference in New Issue