fix(delivery): 增加绑定缓存防频控、发货队列防重试死锁、终止无效回调重试

This commit is contained in:
yml2213
2026-09-18 15:26:09 +08:00
parent ec76844da8
commit 40194fa7e5
5 changed files with 135 additions and 18 deletions
+16 -2
View File
@@ -340,15 +340,29 @@ func (s *CallbackService) dispatchOne(ctx context.Context, id uint) (bool, bool,
"delivered_at": time.Now(),
}).Error
}
applog.Warnf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s status=%d body=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode, truncateCallbackError(string(body)))
if isTerminalCallbackError(resp.StatusCode, string(body)) {
applog.Infof("[callback] push terminal reject (no-retry) event=%s event_id=%s merchant_id=%d url=%s status=%d body=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode, truncateCallbackError(string(body)))
} else {
applog.Warnf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s status=%d body=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode, truncateCallbackError(string(body)))
}
return false, true, s.recordCallbackFailure(delivery, resp.StatusCode, string(body))
}
func isTerminalCallbackError(statusCode int, response string) bool {
if statusCode == http.StatusNotFound {
return true
}
respLower := strings.ToLower(response)
return strings.Contains(respLower, "affiliate_dash_callback_task_not_found") ||
strings.Contains(respLower, "未匹配到本地任务") ||
strings.Contains(respLower, "task_not_found")
}
func (s *CallbackService) recordCallbackFailure(delivery model.CallbackDelivery, statusCode int, response string) error {
attempts := delivery.Attempts + 1
status := model.CallbackDeliveryPending
nextAttempt := time.Now().Add(s.callbackRetryDelay(attempts))
if attempts >= s.maxAttempts {
if attempts >= s.maxAttempts || isTerminalCallbackError(statusCode, response) {
status = model.CallbackDeliveryFailed
nextAttempt = time.Now()
}