2021-01-25 01:14:21 +02:00
|
|
|
package notify
|
|
|
|
|
|
|
|
import (
|
2021-02-18 04:33:30 +02:00
|
|
|
"context"
|
|
|
|
|
2021-01-25 01:14:21 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
2021-02-10 15:51:32 +02:00
|
|
|
// Send calls the underlying notification services to send the given subject and message to their respective endpoints.
|
2021-02-18 04:33:30 +02:00
|
|
|
func (n Notify) Send(ctx context.Context, subject, message string) error {
|
2021-01-25 01:14:21 +02:00
|
|
|
if n.Disabled {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var eg errgroup.Group
|
|
|
|
|
2021-01-25 06:05:28 +02:00
|
|
|
for _, service := range n.notifiers {
|
2021-01-25 01:14:21 +02:00
|
|
|
if service != nil {
|
|
|
|
s := service
|
|
|
|
eg.Go(func() error {
|
2021-02-18 04:33:30 +02:00
|
|
|
return s.Send(ctx, subject, message)
|
2021-01-25 01:14:21 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := eg.Wait()
|
|
|
|
if err != nil {
|
|
|
|
err = errors.Wrap(ErrSendNotification, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|