From f01f9822b89dbad5e3e0b9cf289899915c0104f7 Mon Sep 17 00:00:00 2001 From: Muhammad Abduh Date: Mon, 3 Jun 2024 20:21:29 +0700 Subject: [PATCH] feat(siren): allow not match subscription bulk notifications --- .../notification/dispatch_bulk_notification_service.go | 10 ++++++++++ core/notification/errors.go | 5 ++++- core/notification/router_subscriber_service.go | 9 +-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/notification/dispatch_bulk_notification_service.go b/core/notification/dispatch_bulk_notification_service.go index cf144813..822463b6 100644 --- a/core/notification/dispatch_bulk_notification_service.go +++ b/core/notification/dispatch_bulk_notification_service.go @@ -2,6 +2,7 @@ package notification import ( "context" + "encoding/json" "fmt" "github.com/goto/siren/core/log" @@ -62,6 +63,15 @@ func (s *DispatchBulkNotificationService) prepareMetaMessages(ctx context.Contex generatedMetaMessages, generatedNotificationLogs, err := router.PrepareMetaMessages(ctx, n) if err != nil { + if errors.Is(err, ErrRouteSubscriberNoMatchFound) { + errMessage := fmt.Sprintf("not matching any subscription for notification: %v", n) + nJson, err := json.MarshalIndent(n, "", " ") + if err == nil { + errMessage = fmt.Sprintf("not matching any subscription for notification: %s", string(nJson)) + } + s.deps.Logger.Warn(errMessage) + continue + } return nil, nil, err } diff --git a/core/notification/errors.go b/core/notification/errors.go index fac0776d..2bdabc30 100644 --- a/core/notification/errors.go +++ b/core/notification/errors.go @@ -4,4 +4,7 @@ import ( "errors" ) -var ErrNoMessage = errors.New("no message found") +var ( + ErrNoMessage = errors.New("no message found") + ErrRouteSubscriberNoMatchFound = errors.New("not matching any subscription") +) diff --git a/core/notification/router_subscriber_service.go b/core/notification/router_subscriber_service.go index 8c1e67c5..6e0c92cd 100644 --- a/core/notification/router_subscriber_service.go +++ b/core/notification/router_subscriber_service.go @@ -2,7 +2,6 @@ package notification import ( "context" - "encoding/json" "fmt" "github.com/goto/siren/core/log" @@ -257,18 +256,12 @@ func (s *RouterSubscriberService) PrepareMetaMessages(ctx context.Context, n Not if len(receiversView) == 0 { metricStatus = metricRouterSubscriberStatusMatchNotFound - errMessage := fmt.Sprintf("not matching any subscription for notification: %v", n) - nJson, err := json.MarshalIndent(n, "", " ") - if err == nil { - errMessage = fmt.Sprintf("not matching any subscription for notification: %s", string(nJson)) - } - return nil, nil, errors.ErrInvalid.WithMsgf(errMessage) + return nil, nil, ErrRouteSubscriberNoMatchFound } for _, rcv := range receiversView { metaMessages = append(metaMessages, n.MetaMessage(rcv)) - // messages = append(messages, message) notificationLogs = append(notificationLogs, log.Notification{ NamespaceID: n.NamespaceID, NotificationID: n.ID,