Skip to content

Commit

Permalink
Fix: 抢购普通商品导致无限循环请求详情页触发触发错误
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxXXX95 committed Feb 3, 2021
1 parent 517ba23 commit 0dfdfd6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,19 @@ async function submitOrderProcess(date, skuId, areaId, forceKO = false) {
const allSKUParam = {};
const skuIds = Array.isArray(skuId) ? skuId : [skuId];
const isKOSet = new Set();
const beforeRunTaskMinues = Math.round((date - Date.now()) / 1000 / 60) - 2;
// < 0, 0
// > 6, 6
// range 0-6
let m =
beforeRunTaskMinues < 2
? 2
: beforeRunTaskMinues < 6
? beforeRunTaskMinues
: 6;
while (1) {
let m = 6;
if (Date.now() + m * 60 * 1000 >= date) {
const now = Date.now();
if (now + m * 60 * 1000 >= date) {
for (let i = 0; i < skuIds.length; i++) {
const skuId = skuIds[i];
if (isKOSet.has(skuId)) return;
Expand All @@ -349,12 +359,12 @@ async function submitOrderProcess(date, skuId, areaId, forceKO = false) {
if (i < skuIds.length - 1) {
await new Promise(r => setTimeout(r, 1000));
}
m--;
}
}
if (Date.now() >= date || forceKO) {
if (now >= date || forceKO) {
break;
}
m--;
if (isKOSet.size === skuIds.length || m <= 1) {
// 所有sku都是秒杀商品或者开抢前一分钟没变化
break;
Expand Down

0 comments on commit 0dfdfd6

Please sign in to comment.