Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(siren): allow not match subscription bulk notifications #65

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/notification/dispatch_bulk_notification_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package notification

import (
"context"
"encoding/json"
"fmt"

"github.com/goto/siren/core/log"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion core/notification/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
9 changes: 1 addition & 8 deletions core/notification/router_subscriber_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package notification

import (
"context"
"encoding/json"
"fmt"

"github.com/goto/siren/core/log"
Expand Down Expand Up @@ -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,
Expand Down
Loading