summaryrefslogtreecommitdiff
path: root/service/reload/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-02-23 16:30:31 +0300
committerWolfy-J <[email protected]>2020-02-23 16:30:31 +0300
commit7740e438c5bb78e77919e8dcb5bf86fb5659a75d (patch)
tree5eae9a76635afcfcfb31146495e277a956e1ffd5 /service/reload/service.go
parent3eb34dbfabdb1dd8e158a5fbb3960c12f51c921b (diff)
parent8602c72a17f8ecabef2355d1d24ad569239f7bfa (diff)
Merge remote-tracking branch 'origin/file_watcher_module' into file_watcher_module
Diffstat (limited to 'service/reload/service.go')
-rw-r--r--service/reload/service.go12
1 files changed, 9 insertions, 3 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{}{}
}