From 2258e940b6932dab89c6bbbd106c5c5f7f8b5b6d Mon Sep 17 00:00:00 2001 From: yml2213 Date: Thu, 30 Jul 2026 20:38:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=8E=A8=E9=80=81=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/service/callback.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/internal/service/callback.go b/backend/internal/service/callback.go index 52cdb9c..4a9798d 100644 --- a/backend/internal/service/callback.go +++ b/backend/internal/service/callback.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "io" + "log" "net/http" "net/url" "strings" @@ -236,11 +237,13 @@ func (s *CallbackService) dispatchOne(ctx context.Context, id uint) (bool, bool, resp, err := s.httpClient.Do(req) if err != nil { + log.Printf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s err=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, truncateCallbackError(err.Error())) return false, true, s.recordCallbackFailure(delivery, 0, truncateCallbackError(err.Error())) } defer resp.Body.Close() body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices { + log.Printf("[callback] push ok event=%s event_id=%s merchant_id=%d url=%s status=%d", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode) return true, true, s.db.Model(&model.CallbackDelivery{}).Where("id = ?", delivery.ID).Updates(map[string]interface{}{ "status": model.CallbackDeliveryDelivered, "attempts": delivery.Attempts + 1, @@ -249,6 +252,7 @@ func (s *CallbackService) dispatchOne(ctx context.Context, id uint) (bool, bool, "delivered_at": time.Now(), }).Error } + log.Printf("[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)) } @@ -273,7 +277,12 @@ func (s *CallbackService) Run(ctx context.Context) { ticker := time.NewTicker(3 * time.Second) defer ticker.Stop() for { - _, _, _ = s.DispatchDue(ctx, 50) + successes, failures, err := s.DispatchDue(ctx, 50) + if err != nil { + log.Printf("[callback] dispatch error: %v", err) + } else if successes > 0 || failures > 0 { + log.Printf("[callback] dispatch done successes=%d failures=%d", successes, failures) + } select { case <-ctx.Done(): return