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 return
} }
err = InitNotificationManager() notificationManager, err = InitNotificationManager()
if err != nil { if err != nil {
err = werr.Wrap(err).Log() err = werr.Wrap(err).Log()
logger.Error("notification", "error", err) logger.Error("notification", "error", err)

View File

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