aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2018-11-16 20:09:31 +0100
committerGibheer <gibheer+git@zero-knowledge.org>2018-11-16 20:09:31 +0100
commit1960907547d5da614a73ea35247bbaf771ced3c5 (patch)
tree722c4b28fc0d5265a6d9dba656cdbd147a0a146d /cmd
parentf759b2f9931d2f2b9d80a32dda0dd04c0de00d5e (diff)
moncheck - adjust queries to take less data
With selecting only the bare minimum we get much nicer performance.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/moncheck/main.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go
index ca31a02..dba3099 100644
--- a/cmd/moncheck/main.go
+++ b/cmd/moncheck/main.go
@@ -64,7 +64,7 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
log.Printf("[%d] could not start transaction: %s", thread, err)
continue
}
- rows, err := tx.Query("select check_id, check_id, cmdLine, states, next_time from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
+ rows, err := tx.Query("select check_id, cmdLine, states, notify from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
if err != nil {
log.Printf("[%d] could not start query: %s", thread, err)
tx.Rollback()
@@ -128,12 +128,16 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
states = append([]int64{0}, states[:statePos]...)
}
- if _, err := tx.Exec("update active_checks set next_time = now() + interval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
+ if _, err := tx.Exec("update active_checks set next_time = now() + intval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
+ tx.Rollback()
+ continue
}
if notify {
- if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", id, pq.Array(&states), &output); err != nil {
+ if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", &id, pq.Array(&states), output.Bytes()); err != nil {
log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
+ tx.Rollback()
+ continue
}
}
tx.Commit()