conf: 同步触发规则
parent
997e9adbeb
commit
773ef97a27
@ -1,98 +1,151 @@
|
|||||||
const { scheduleJob } = require('node-schedule');
|
const { scheduleJob } = require('node-schedule');
|
||||||
const heytripService = require('../services/heytripService');
|
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
|
* 获取可用的酒店id
|
||||||
*/
|
*/
|
||||||
const Aids = () => {
|
const Aids = () => {
|
||||||
return false;
|
return false;
|
||||||
// const jobA = scheduleJob('*/2 * * * * *', async function () {
|
// const jobA = scheduleJob('*/2 * * * * *', async function () {
|
||||||
const jobA = scheduleJob('0 0 0 * * *', async function () {
|
// const jobA = scheduleJob('0 0 0 * * *', async function () {
|
||||||
console.log('syncing heytrip, get available accommodation ids.');
|
// console.log('syncing heytrip, get available accommodation ids.');
|
||||||
const isRunning = jobA.pendingInvocations[0]?.job?.running == 1;
|
// const isRunning = jobA.pendingInvocations[0]?.job?.running == 1;
|
||||||
if (!isRunning) {
|
// if (!isRunning) {
|
||||||
const res = await heytripService.syncAids();
|
// const res = await heytripService.syncAids();
|
||||||
if (res.nextPage !== true) {
|
// if (res.nextPage !== true) {
|
||||||
console.log('job completed! canceled job!');
|
// console.log('job completed! canceled job!');
|
||||||
jobA.cancel();
|
// jobA.cancel();
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
console.log('pre job running! cancelNext');
|
// console.log('pre job running! cancelNext');
|
||||||
jobA.cancelNext();
|
// jobA.cancelNext();
|
||||||
}
|
// }
|
||||||
|
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新酒店的状态, 是否下架
|
* 更新酒店的状态, 是否下架
|
||||||
|
* 每天启动同步;
|
||||||
|
* * 每次同步需要3000+页
|
||||||
*/
|
*/
|
||||||
const AidsState = () => {
|
const AidsState = () => {
|
||||||
const jobAS = scheduleJob('*/2 * * * * *', async function () {
|
const dailyJob = scheduleJob('0 0 0 * * *', async function () {
|
||||||
// const jobAS = scheduleJob('0 5 0 * * *', async function () {
|
const jobAS = scheduleJob('*/2 * * * * *', async function () {
|
||||||
console.log('--------------------syncing heytrip, get available accommodation ids.--------------------');
|
console.log('--------------------syncing heytrip, get available accommodation ids.--------------------');
|
||||||
const isRunning = jobAS.pendingInvocations[0]?.job?.running == 1;
|
const isRunning = jobAS.pendingInvocations[0]?.job?.running == 1;
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
const res = await heytripService.syncAidState();
|
const res = await heytripService.syncAidState();
|
||||||
// jobAS.cancel(); // debug: 0
|
// jobAS.cancel(); // debug: 0
|
||||||
if (res.nextPage !== true) {
|
if (res.nextPage !== true) {
|
||||||
console.log('job completed! canceled job[AidsState]!');
|
console.log('job completed! canceled job[AidsState]!');
|
||||||
jobAS.cancel();
|
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 = () => {
|
const hotelLgcDetails = () => {
|
||||||
// return false;
|
// return false;
|
||||||
const job2 = scheduleJob('*/4 * * * * *', async function () {
|
const dailyJob2 = scheduleJob('0 5 20 * * 5', async function () {
|
||||||
console.log('-------------------------syncing heytrip, get accommodation details.-------------------------');
|
const job2 = scheduleJob('*/5 * * * * *', async function () {
|
||||||
|
console.log('-------------------------syncing heytrip, get accommodation details.-------------------------');
|
||||||
|
|
||||||
const isRunning = job2.pendingInvocations[0]?.job?.running == 1;
|
const isRunning = job2.pendingInvocations[0]?.job?.running == 1;
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
const res = await heytripService.newHotelsLgc('1');
|
const res = await heytripService.newHotelsLgc('1');
|
||||||
|
|
||||||
// job2.cancel(); // debug: 0
|
// job2.cancel(); // debug: 0
|
||||||
if (res.next !== true) {
|
if (res.next !== true) {
|
||||||
job2.cancel();
|
job2.cancel(res.restart);
|
||||||
console.log('job completed! canceled job[hotelLgcDetails]!');
|
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 = () => {
|
const chinaHotelDetails = () => {
|
||||||
return false;
|
// return false;
|
||||||
const job3 = scheduleJob('*/4 * * * * *', async function () {
|
const dailyJobCN = scheduleJob('0 5 20 * * 6', async function () {
|
||||||
console.log('syncing heytrip, get china accommodation details.');
|
const job3 = scheduleJob('*/4 * * * * *', async function () {
|
||||||
const isRunning = job3.pendingInvocations[0]?.job?.running == 1;
|
console.log('-------------------------syncing heytrip, get china accommodation details.-------------------------');
|
||||||
if (!isRunning) {
|
const isRunning = job3.pendingInvocations[0]?.job?.running == 1;
|
||||||
const res = await heytripService.chinaHotelsLgc2('2');
|
if (!isRunning) {
|
||||||
if (res.next !== true) {
|
const res = await heytripService.chinaHotelsLgc2('2');
|
||||||
job3.cancel();
|
// job3.cancel(); // debug: 0
|
||||||
console.log('job completed! canceled job!');
|
if (res.next !== true) {
|
||||||
// job3.reschedule('0 0 0 * * *');
|
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 = {
|
module.exports = {
|
||||||
Aids, AidsState,
|
Aids, AidsState,
|
||||||
hotelLgcDetails, chinaHotelDetails
|
newHotelDetails, hotelLgcDetails, chinaHotelDetails
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue