Nicer notification manager initialization

This commit is contained in:
Magnus Åhall 2024-05-05 10:12:21 +02:00
parent 49af9dc33c
commit 5f6a48e7e0
2 changed files with 7 additions and 8 deletions

View File

@ -100,7 +100,7 @@ func main() { // {{{
return
}
err = InitNotificationManager()
notificationManager, err = InitNotificationManager()
if err != nil {
err = werr.Wrap(err).Log()
logger.Error("notification", "error", err)

View File

@ -8,7 +8,6 @@ import (
"smon/notification"
// Standard
"database/sql"
"encoding/json"
)
@ -19,11 +18,9 @@ type DbNotificationService struct {
Prio int
}
func InitNotificationManager() (err error) { // {{{
func InitNotificationManager() (nm notification.Manager, err error) { // {{{
var dbServices []DbNotificationService
var row *sql.Row
row = service.Db.Conn.QueryRow(`
row := service.Db.Conn.QueryRow(`
WITH services AS (
SELECT
id,
@ -51,7 +48,7 @@ func InitNotificationManager() (err error) { // {{{
return
}
notificationManager = notification.NewManager(logger)
nm = notification.NewManager(logger)
var service notification.Service
for _, dbService := range dbServices {
service, err = notification.ServiceFactory(
@ -65,16 +62,18 @@ func InitNotificationManager() (err error) { // {{{
if err != nil {
err = werr.Wrap(err).WithData(dbService.Service)
}
notificationManager.AddService(service)
nm.AddService(service)
}
return
} // }}}
func AcknowledgeNotification(uuid string) (err error) { // {{{
/*
_, err = service.Db.Conn.Exec(`UPDATE schedule SET acknowledged=true WHERE schedule_uuid=$1`, uuid)
if err != nil {
err = werr.Wrap(err).WithData(uuid)
}
*/
return
} // }}}