fix: 合入后修正迁移计数并唤醒回执推送

This commit is contained in:
Nixevol
2026-09-30 16:30:27 +08:00
parent cb9512fe11
commit 8f2ebc7d21
6 changed files with 71 additions and 16 deletions
+12 -3
View File
@@ -50,10 +50,13 @@ func (a *App) ExpireOnce(ctx context.Context, nowMs int64) error {
if time.Now().After(deadline) {
return nil
}
n, err := a.expireOnceBatch(ctx, nowMs)
n, senders, err := a.expireOnceBatch(ctx, nowMs)
if err != nil {
return err
}
for _, s := range senders {
a.WakePush(s)
}
if n == 0 {
break
}
@@ -62,8 +65,9 @@ func (a *App) ExpireOnce(ctx context.Context, nowMs int64) error {
return nil
}
func (a *App) expireOnceBatch(ctx context.Context, nowMs int64) (int, error) {
func (a *App) expireOnceBatch(ctx context.Context, nowMs int64) (int, []string, error) {
var n int
var senders []string
err := a.db.Queue.Do(ctx, func(tx *sql.Tx) error {
if err := a.fillZombieExpireTx(tx, nowMs); err != nil {
return err
@@ -94,6 +98,7 @@ LIMIT ?`, nowMs, expireBatch)
}
_ = rows.Close()
n = len(list)
seen := map[string]struct{}{}
for _, it := range list {
state := DeliveryDropped
reason := ReasonOffline
@@ -104,10 +109,14 @@ LIMIT ?`, nowMs, expireBatch)
if err := a.finishDeliveryTx(tx, it.seq, it.endpointID, it.senderID, it.msgID, state, reason, false, nowMs); err != nil {
return err
}
if _, ok := seen[it.senderID]; !ok {
seen[it.senderID] = struct{}{}
senders = append(senders, it.senderID)
}
}
return finalizeStuckDispatchedTx(tx, nowMs, a.lim.RecordRetentionDays)
})
return n, err
return n, senders, err
}
func (a *App) fillZombieExpireTx(tx *sql.Tx, nowMs int64) error {