diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-08-12 14:49:53 +0200 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-08-12 14:49:53 +0200 |
commit | e2b479c34fcee4c41009fc9e8fe869831fbd494f (patch) | |
tree | 465ba149ff5e25e853e4dd5d758298a7fd97d59a /cmd/moncheck/main.go | |
parent | 88b50033d0e9808a4657ff56835c6dacc77cd433 (diff) |
support new checker api
With this, it is now possible to support multiple check instances and
balance the load.
Diffstat (limited to 'cmd/moncheck/main.go')
-rw-r--r-- | cmd/moncheck/main.go | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index 6aa34a5..3bac52e 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -27,11 +27,12 @@ var ( type ( Config struct { - DB string `json:"db"` - Timeout string `json:"timeout"` - Wait string `json:"wait"` - Path []string `json:"path"` - Workers int `json:"workers"` + DB string `json:"db"` + Timeout string `json:"timeout"` + Wait string `json:"wait"` + Path []string `json:"path"` + Workers int `json:"workers"` + CheckerID int `json:"checker_id"` } States []int @@ -73,14 +74,14 @@ func main() { } for i := 0; i < config.Workers; i++ { - go check(i, db, waitDuration, timeout, hostname) + go check(i, db, waitDuration, timeout, hostname, config.CheckerID) } wg := sync.WaitGroup{} wg.Add(1) wg.Wait() } -func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname string) { +func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname string, checker_id int) { for { tx, err := db.Begin() if err != nil { @@ -91,14 +92,10 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname from active_checks where next_time < now() and enabled + and checker_id = $1 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() - continue - } + limit 1;`, checker_id) var ( id int64 cmdLine []string |