diff options
author | Wolfy-J <[email protected]> | 2020-02-23 16:30:31 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2020-02-23 16:30:31 +0300 |
commit | 7740e438c5bb78e77919e8dcb5bf86fb5659a75d (patch) | |
tree | 5eae9a76635afcfcfb31146495e277a956e1ffd5 | |
parent | 3eb34dbfabdb1dd8e158a5fbb3960c12f51c921b (diff) | |
parent | 8602c72a17f8ecabef2355d1d24ad569239f7bfa (diff) |
Merge remote-tracking branch 'origin/file_watcher_module' into file_watcher_module
-rw-r--r-- | service/reload/service.go | 12 | ||||
-rw-r--r-- | service/reload/watcher.go | 5 |
2 files changed, 13 insertions, 4 deletions
diff --git a/service/reload/service.go b/service/reload/service.go index 2aaed8ad..73e20085 100644 --- a/service/reload/service.go +++ b/service/reload/service.go @@ -109,9 +109,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) } }() @@ -124,6 +121,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 { @@ -154,4 +159,5 @@ func (s *Service) Serve() error { func (s *Service) Stop() { s.watcher.Stop() + s.stopc <- struct{}{} } diff --git a/service/reload/watcher.go b/service/reload/watcher.go index d5211d19..a3b8fe1f 100644 --- a/service/reload/watcher.go +++ b/service/reload/watcher.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "sync" "time" ) @@ -225,7 +226,9 @@ func (w *Watcher) waitEvent(d time.Duration) error { select { case <-w.close: ticker.Stop() - return nil + // just exit + // no matter for the pollEvents + runtime.Goexit() case <-ticker.C: // this is not very effective way // because we have to wait on Lock |