Skip to content

Commit

Permalink
Fix get subs & revert database interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kolkov committed Mar 9, 2021
1 parent adf9b18 commit f28ce9f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
4 changes: 0 additions & 4 deletions database/redis/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ func (connector *DbConnector) GetTagsSubscriptions(tags []string) ([]*moira.Subs
return connector.GetSubscriptions(subscriptionsIDs)
}

func (connector *DbConnector) GetSubscriptionsByContact(contactID string) ([]*moira.SubscriptionData, error) {
return nil, fmt.Errorf("not implemented yet") //TODO
}

func (connector *DbConnector) getSubscriptionsIDsByTags(tags []string) ([]string, error) {
c := connector.pool.Get()
defer c.Close()
Expand Down
1 change: 0 additions & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ type Database interface {
RemoveSubscription(subscriptionID string) error
GetUserSubscriptionIDs(userLogin string) ([]string, error)
GetTagsSubscriptions(tags []string) ([]*SubscriptionData, error)
GetSubscriptionsByContact(contactID string) ([]*SubscriptionData, error)

// ScheduledNotification storing
GetNotifications(start, end int64) ([]*ScheduledNotification, int64, error)
Expand Down
17 changes: 1 addition & 16 deletions mock/moira-alert/database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ func (notifier *StandardNotifier) runSender(sender moira.Sender, ch chan Notific
switch e := err.(type) {
case moira.SenderBrokenContactError:
log.Errorf("Cannot send to broken contact: %s", e.Error())

brokenContact := pkg.Contact.ID
if count, errorDisabling := disableBrokenContactSubscriptions(brokenContact, notifier.database, log); errorDisabling != nil {
if count, errorDisabling := disableBrokenContactSubscriptions(&pkg.Contact, notifier.database, log); errorDisabling != nil {
log.Errorf("Failed to disable broken subscriptions: ", errorDisabling)
} else {
notifier.metrics.SubsBrokenDisabled.Mark(int64(count))
Expand All @@ -212,17 +210,21 @@ func (notifier *StandardNotifier) runSender(sender moira.Sender, ch chan Notific
}
}

func disableBrokenContactSubscriptions(brokenContact string, database moira.Database, log moira.Logger) (
func disableBrokenContactSubscriptions(brokenContact *moira.ContactData, database moira.Database, log moira.Logger) (
disabledCount int, e error) {
subs, err := database.GetSubscriptionsByContact(brokenContact)
subsIDs, err := database.GetUserSubscriptionIDs(brokenContact.User)
if err != nil {
return 0, err
}
subs, e := database.GetSubscriptions(subsIDs)
if e != nil {
return 0, e
}

disableSubs := []*moira.SubscriptionData{}
for _, s := range subs {
if len(s.Contacts) == 1 {
if s.Contacts[0] == brokenContact {
if s.Contacts[0] == brokenContact.ID {
s.Enabled = false
disableSubs = append(disableSubs, s)
}
Expand Down

0 comments on commit f28ce9f

Please sign in to comment.