OSDN Git Service

add
authorHAOYUatHZ <haoyu@protonmail.com>
Fri, 2 Aug 2019 08:45:23 +0000 (16:45 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Fri, 2 Aug 2019 08:45:23 +0000 (16:45 +0800)
toolbar/precog/config/config.go
toolbar/precog/monitor/monitor.go

index efa9673..2113e95 100644 (file)
@@ -34,10 +34,11 @@ func NewConfigWithPath(path string) *Config {
 }
 
 type Config struct {
-       MySQLConfig common.MySQLConfig `json:"mysql"`
-       Policy      Policy             `json:"policy"`
-       Nodes       []Node             `json:"bootstrap_nodes"`
-       API         API                `json:"api"`
+       MySQLConfig      common.MySQLConfig `json:"mysql"`
+       CheckFreqSeconds uint64             `json:"check_seconds"`
+       Policy           Policy             `json:"policy"`
+       Nodes            []Node             `json:"bootstrap_nodes"`
+       API              API                `json:"api"`
 }
 
 type Policy struct {
index fcfa9a7..10b8168 100644 (file)
@@ -9,9 +9,6 @@ import (
        "github.com/vapor/toolbar/precog/config"
 )
 
-// TODO: put in cfg?
-const checkFreqSeconds = 60
-
 type monitor struct {
        cfg *config.Config
        db  *gorm.DB
@@ -29,7 +26,7 @@ func (m *monitor) Run() {
                log.Fatal(err)
        }
 
-       ticker := time.NewTicker(checkFreqSeconds * time.Second)
+       ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
        for ; true; <-ticker.C {
                // TODO: lock?
                m.monitorRountine()