Switched to purer libraries
This commit is contained in:
parent
8fa8bb4c3a
commit
9496947f01
21 changed files with 390 additions and 316 deletions
27
nodata.go
27
nodata.go
|
|
@ -2,13 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
// External
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
werr "git.ahall.se/go/wrappederror"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
// Internal
|
||||
"smon/notification"
|
||||
|
||||
// Standard
|
||||
"database/sql"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -24,7 +25,7 @@ func nodataLoop() {
|
|||
var datapoints []Datapoint
|
||||
var err error
|
||||
|
||||
ticker := time.NewTicker(time.Second * time.Duration(fileConf.NodataInterval))
|
||||
ticker := time.NewTicker(time.Second * time.Duration(config.NodataInterval))
|
||||
for {
|
||||
<-ticker.C
|
||||
datapoints, err = nodataDatapoints()
|
||||
|
|
@ -62,7 +63,8 @@ func nodataNotify(datapoint Datapoint, state string) (err error) {
|
|||
} else {
|
||||
errBody = nil
|
||||
}
|
||||
_, err = service.Db.Conn.Exec(
|
||||
_, err = db.Exec(
|
||||
context.Background(),
|
||||
`
|
||||
INSERT INTO notification_send(notification_id, datapoint_nodata_id, uuid, ok, error)
|
||||
SELECT
|
||||
|
|
@ -93,8 +95,9 @@ func nodataNotify(datapoint Datapoint, state string) (err error) {
|
|||
func nodataDatapoints() (datapoints []Datapoint, err error) {
|
||||
datapoints = []Datapoint{}
|
||||
|
||||
var rows *sql.Rows
|
||||
rows, err = service.Db.Conn.Query(`
|
||||
rows, _ := db.Query(
|
||||
context.Background(),
|
||||
`
|
||||
UPDATE datapoint
|
||||
SET
|
||||
nodata_is_problem = true
|
||||
|
|
@ -114,20 +117,12 @@ func nodataDatapoints() (datapoints []Datapoint, err error) {
|
|||
datapoint.id,
|
||||
datapoint.name
|
||||
|
||||
`)
|
||||
`)
|
||||
datapoints, err = pgx.CollectRows(rows, pgx.RowToStructByName[Datapoint])
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var dp Datapoint
|
||||
for rows.Next() {
|
||||
if err = rows.Scan(&dp.ID, &dp.Name); err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
datapoints = append(datapoints, dp)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue