fix(订单通知): 冻结批次允许 5 秒准备偏差,修复整批未发送后超时取消

- 调度在截止后 60 秒窗口内冻结时,实际写入时间可能比 cutoff+60s 晚几百毫秒
- 发送前校验用 createdAt > cutoff+60s 直接跳过,导致三个批次整批不发,30 分钟后按队列超时取消
- 增加 5 秒容差,仅影响冻结批次的可发送判定,不改变采集窗口
This commit is contained in:
刘欢 committed 2026-12-01 13:36:03 +08:00
1 parent 772602aa18
commit 7f61fe29da
1 file changed
+1 -1
+1 -1
View File
@@ -65,7 +65,7 @@ class OrderRuleDispatcher{
const legacyStart=new Date(Date.parse(batch.cutoff)+8*3600000).toISOString().slice(0,10)+'T00:00:00+08:00';
if(!batch.window||batch.window.end!==expected.end||![Date.parse(expected.start),Date.parse(legacyStart)].includes(Date.parse(batch.window.start))||batch.window.startInclusive!==true||batch.window.endInclusive!==false)continue;
const grace=batch.intakeGrace?.cutoff===batch.cutoff&&Date.parse(batch.intakeGrace.expiresAt)===Date.parse(batch.cutoff)+1800000&&Date.parse(batch.createdAt)<=Date.parse(batch.intakeGrace.expiresAt)&&batch.orderIds?.every(id=>{const order=this.store.get('orders',id);return order&&(this.store.intakeWindow(order.sample||order.event)?.end===batch.cutoff||require('./carry-forward.cjs').windowForOrder(this.store,order,modeOf(batch))?.end===batch.cutoff);});
if(batch.createdAt&&(Date.parse(batch.createdAt)>Date.parse(batch.cutoff)+60000&&!grace||Date.parse(batch.createdAt)<Date.parse(batch.cutoff)))continue;if(await this.dispatch(freeze(structuredClone(batch)),config)===false)continue;}
const prepareSkewMs=5000;if(batch.createdAt&&(Date.parse(batch.createdAt)>Date.parse(batch.cutoff)+60000+prepareSkewMs&&!grace||Date.parse(batch.createdAt)<Date.parse(batch.cutoff)))continue;if(await this.dispatch(freeze(structuredClone(batch)),config)===false)continue;}
});}catch(error){this.store.recordIssue?.('dispatch:'+String(cutoff),{component:'mail',error:error.message,cutoff});if(error.status!==409)throw error;}
// Keep the current slot during its collection allowance so repaired categories retry.
if(cutoff&&this.clock()-Date.parse(cutoff)>60000)this.schedule={signature,next:nextSlots(schedule,this.clock(),1,calendar)[0]};