mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 19:54:44 -07:00
cache previously created signal groups better for potential re-use
This commit is contained in:
parent
6fb5babf87
commit
3fa96bbfa6
3 changed files with 23 additions and 10 deletions
|
|
@ -45,10 +45,16 @@ func (s *Sender) CreateDefaultSignalSubscription(appName string) (*notification.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ¬ification.SignalSubscription{
|
signalSub := ¬ification.SignalSubscription{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
Account: account,
|
Account: account,
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
if err := s.store.SaveSignalGroup(appName, signalSub); err != nil {
|
||||||
|
s.logger.Warn("Failed to cache Signal group", "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return signalSub, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) Send(sub *notification.Subscription, notif notification.Notification) error {
|
func (s *Sender) Send(sub *notification.Subscription, notif notification.Notification) error {
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,7 @@ func (d *Dispatcher) Send(appName string, notif Notification) error {
|
||||||
for _, sub := range app.Subscriptions {
|
for _, sub := range app.Subscriptions {
|
||||||
sender, ok := d.senders[sub.Channel]
|
sender, ok := d.senders[sub.Channel]
|
||||||
if !ok {
|
if !ok {
|
||||||
d.logger.Error("No sender for channel", "channel", sub.Channel, "subscriptionID", sub.ID)
|
d.logger.Debug("Skipping subscription for disabled channel", "channel", sub.Channel, "subscriptionID", sub.ID)
|
||||||
lastErr = fmt.Errorf("no sender for channel: %s", sub.Channel)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,9 +194,21 @@ func (d *Dispatcher) trySignalAutoConfig(appName string) (*App, error) {
|
||||||
return nil, fmt.Errorf("sender does not implement signal auto-configuration")
|
return nil, fmt.Errorf("sender does not implement signal auto-configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
signalSub, err := autoConfigurer.CreateDefaultSignalSubscription(appName)
|
var signalSub *SignalSubscription
|
||||||
|
|
||||||
|
cachedGroup, err := d.store.GetSignalGroup(appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
d.logger.Warn("Failed to check for cached Signal group", "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cachedGroup != nil {
|
||||||
|
d.logger.Debug("Reusing cached Signal group", "app", appName)
|
||||||
|
signalSub = cachedGroup
|
||||||
|
} else {
|
||||||
|
signalSub, err = autoConfigurer.CreateDefaultSignalSubscription(appName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subID, err := GenerateSubscriptionID()
|
subID, err := GenerateSubscriptionID()
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,6 @@ func (s *Server) handleCreateSubscription(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sub.Signal = signalSub
|
sub.Signal = signalSub
|
||||||
|
|
||||||
if err := s.store.SaveSignalGroup(appName, signalSub); err != nil {
|
|
||||||
s.logger.Warn("Failed to cache Signal group", "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue