Hold stale tender notification retries for review

This commit is contained in:
2026-09-06 13:19:55 +03:00
parent 02625906f2
commit 1fbf77c0ac
6 changed files with 73 additions and 4 deletions
+10 -1
View File
@@ -206,7 +206,8 @@ export function reserveDelivery(subscriptionId,payload,tenderIds,{clock=Date.now
db.prepare("INSERT INTO notification_outbox(id,subscription_id,payload,tender_ids,state) VALUES (?,?,?,?,'pending')").run(id,subscriptionId,JSON.stringify(payload),JSON.stringify(tenderIds));
row=db.prepare('SELECT * FROM notification_outbox WHERE id=?').get(id);
}
if(row.state==='uncertain'||(row.first_attempt!==null&&clock-row.first_attempt>=23*3600000)){
if(row.state==='uncertain'){db.exec('COMMIT');return {blocked:true};}
if(row.first_attempt!==null&&clock-row.first_attempt>=23*3600000){
db.prepare("UPDATE notification_outbox SET state='uncertain',error=? WHERE id=?").run('Gönderim sonucu belirsiz; sağlayıcı kaydı kontrol edilmeden tekrar gönderilmez.',row.id);
db.exec('COMMIT');return {blocked:true};
}
@@ -237,6 +238,14 @@ export function failDelivery(delivery,error) {
finally{db.close();}
}
/** Stop replay without altering the pinned request or acknowledging delivery. */
export function holdDelivery(delivery,reason) {
const db=open();
try{return db.prepare("UPDATE notification_outbox SET state='uncertain',error=? WHERE id=? AND lease=? AND state='sending'")
.run(String(reason),delivery.id,delivery.lease).changes>0;}
finally{db.close();}
}
export function deliveryQueue() {
const db=open();
try{return db.prepare("SELECT o.*,r.actor,r.action,r.note,r.reviewed_at FROM notification_outbox o LEFT JOIN notification_outbox_reviews r ON r.id=o.id WHERE o.state IN ('pending','sending','uncertain','sent_manual','skipped') ORDER BY o.first_attempt DESC LIMIT 50").all().map(row=>{