Switched to purer libraries
This commit is contained in:
parent
8fa8bb4c3a
commit
9496947f01
21 changed files with 390 additions and 316 deletions
|
|
@ -2,13 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
// External
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
"github.com/jmoiron/sqlx"
|
||||
werr "git.ahall.se/go/wrappederror"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
// Internal
|
||||
"smon/notification"
|
||||
|
||||
// Standard
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
|
@ -30,19 +31,24 @@ type NotificationSend struct {
|
|||
func notificationLog(notificationService *notification.Service, problemID int, err error) {
|
||||
if err == nil {
|
||||
logger.Info("notification", "service", (*notificationService).GetType(), "problemID", problemID, "prio", (*notificationService).GetPrio(), "ok", true)
|
||||
service.Db.Conn.Query(
|
||||
_, dbErr := db.Exec(
|
||||
context.Background(),
|
||||
`
|
||||
INSERT INTO notification_send()
|
||||
`,
|
||||
)
|
||||
if dbErr != nil {
|
||||
logger.Error("notification", "op", "notification_send", "error", werr.Wrap(err))
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.Error("notification", "service", (*notificationService).GetType(), "problemID", problemID, "prio", (*notificationService).GetPrio(), "ok", false, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func notificationsSent(from, to time.Time) (nss []NotificationSend, err error) {
|
||||
var rows *sqlx.Rows
|
||||
rows, err = service.Db.Conn.Queryx(
|
||||
rows, _ := db.Query(
|
||||
context.Background(),
|
||||
`
|
||||
SELECT
|
||||
n.prio,
|
||||
|
|
@ -71,15 +77,8 @@ func notificationsSent(from, to time.Time) (nss []NotificationSend, err error) {
|
|||
from,
|
||||
to,
|
||||
)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
ns := NotificationSend{}
|
||||
err = rows.StructScan(&ns)
|
||||
nss, err = pgx.CollectRows(rows, func(row pgx.CollectableRow) (ns NotificationSend, err error) {
|
||||
ns, err = pgx.RowToStructByName[NotificationSend](row)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
|
|
@ -93,7 +92,12 @@ func notificationsSent(from, to time.Time) (nss []NotificationSend, err error) {
|
|||
j, err = json.MarshalIndent(foo, "", " ")
|
||||
ns.ErrorIndented = string(j)
|
||||
|
||||
nss = append(nss, ns)
|
||||
return
|
||||
})
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue