aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/moncheck/main.go26
1 files changed, 8 insertions, 18 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go
index 3080309..7253c07 100644
--- a/cmd/moncheck/main.go
+++ b/cmd/moncheck/main.go
@@ -87,7 +87,7 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname
log.Printf("[%d] could not start transaction: %s", thread, err)
continue
}
- rows, err := tx.Query(`select check_id, cmdLine, states, mapping_id
+ row := tx.QueryRow(`select check_id, cmdLine, states, mapping_id
from active_checks
where next_time < now()
and enabled
@@ -106,25 +106,15 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname
mapId int
state int
)
- found := false
- for rows.Next() {
- if err := rows.Err(); err != nil {
- log.Printf("could not fetch row: %s", err)
- tx.Rollback()
- break
- }
- err := rows.Scan(&id, pq.Array(&cmdLine), &states, &mapId)
- if err != nil {
- log.Printf("could not scan values: %s", err)
- tx.Rollback()
- break
- }
- found = true
- }
- if !found {
- time.Sleep(waitDuration)
+ err = row.Scan(&id, pq.Array(&cmdLine), &states, &mapId)
+ if err != nil && err == sql.ErrNoRows {
tx.Rollback()
+ time.Sleep(waitDuration)
continue
+ } else if err != nil {
+ log.Printf("could not scan values: %s", err)
+ tx.Rollback()
+ break
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
cmd := exec.CommandContext(ctx, cmdLine[0], cmdLine[1:]...)