summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-02-23 16:13:54 +0300
committerValery Piashchynski <[email protected]>2020-02-23 16:13:54 +0300
commit88c13f9709bbb0033dddca21e181a5d62f7317e7 (patch)
treee243ce7ccf438dd941175ae5cd7233bf83f3619d
parent42b897b3e6ec564402dbe35c1ec0a0f5d99ef511 (diff)
Remove data race
Smart restart
-rw-r--r--service/reload/service.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/service/reload/service.go b/service/reload/service.go
index a8e862cb..d5b6a024 100644
--- a/service/reload/service.go
+++ b/service/reload/service.go
@@ -111,9 +111,6 @@ func (s *Service) Serve() error {
serviceConfig ServiceConfig
service string
}{serviceConfig: s.cfg.Services[e.service], service: e.service}
-
- ticker.Stop()
- ticker = time.NewTicker(s.cfg.Interval)
}
}()
@@ -126,6 +123,14 @@ func (s *Service) Serve() error {
case config := <-treshholdc:
// replace previous value in map by more recent without adding new one
updated[config.service] = config.serviceConfig
+ // stop ticker
+ ticker.Stop()
+ // restart
+ // logic is following:
+ // if we getting a lot of events, we should't restart particular service on each of it (user doing bug move or very fast typing)
+ // instead, we are resetting the ticker and wait for Interval time
+ // If there is no more events, we restart service only once
+ ticker = time.NewTicker(s.cfg.Interval)
case <-ticker.C:
if len(updated) > 0 {
for k, v := range updated {