diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daq/s5proxy/src/s5proxy/config.go | 20 | ||||
-rw-r--r-- | src/daq/s5proxy/src/s5proxy/stats.go | 9 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/daq/s5proxy/src/s5proxy/config.go b/src/daq/s5proxy/src/s5proxy/config.go index c36d60d..8a94c48 100644 --- a/src/daq/s5proxy/src/s5proxy/config.go +++ b/src/daq/s5proxy/src/s5proxy/config.go @@ -93,16 +93,18 @@ type HeaderOperation struct { Value string `json:"value,omitempty"` } -type Duration struct { - Value time.Duration -} +type Duration int64 -func (d *Duration) UnmarshalText(data []byte) (err error) { - d.Value, err = time.ParseDuration(string(data)) - if err == nil && d.Value < 0 { - err = errors.New("negative durations are not allowed") +func (d *Duration) UnmarshalText(data []byte) error { + v, err := time.ParseDuration(string(data)) + if err != nil { + return err } - return + if v < 1*time.Second { + return errors.New("duration must be >= 1s") + } + *d = Duration(v / time.Millisecond) + return nil } type SFiveConf struct { @@ -134,7 +136,7 @@ func readConfig(configfile string) (conf *Config, err error) { defer f.Close() conf = &Config{} - conf.SFive.Duration.Value = 10 * time.Second + conf.SFive.Duration = 10000 err = json.NewDecoder(f).Decode(conf) return } diff --git a/src/daq/s5proxy/src/s5proxy/stats.go b/src/daq/s5proxy/src/s5proxy/stats.go index ddc3885..7b291b7 100644 --- a/src/daq/s5proxy/src/s5proxy/stats.go +++ b/src/daq/s5proxy/src/s5proxy/stats.go @@ -211,18 +211,19 @@ func (s *Stats) Run() (err error) { go worker.Run() } - offset := s.conf.SFive.Duration.Value - (time.Duration(time.Now().UnixNano()) % (s.conf.SFive.Duration.Value)) + d := time.Duration(s.conf.SFive.Duration) * time.Millisecond + offset := d - (time.Duration(time.Now().UnixNano()) % d) s5l.Printf("STATS: waiting %v for the next duration boundary", offset) time.Sleep(offset) s5l.Printf("STATS: starting ticker") - ticker := time.NewTicker(s.conf.SFive.Duration.Value) + ticker := time.NewTicker(d) for _, worker := range s.workers { worker.trigger <- time.Unix(0, 0) // stats-worker will not send data but just reset } for { select { case t := <-ticker.C: - t = t.Add(-1 * s.conf.SFive.Duration.Value) + t = t.Add(-1 * d) for _, worker := range s.workers { worker.trigger <- t } @@ -230,7 +231,7 @@ func (s *Stats) Run() (err error) { upd.Version = 1 upd.Hostname = s.conf.SFive.Hostname upd.Tags = s.conf.SFive.Tags - upd.Duration = int64(s.conf.SFive.Duration.Value / time.Millisecond) + upd.Duration = int64(s.conf.SFive.Duration) s5l.Printf("STATS: got data update for '%v'", upd) // TODO: send it out on socket // TODO: if sock error ... try reconnect |