summaryrefslogtreecommitdiff
path: root/service/reload/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-02-23 14:14:05 +0300
committerWolfy-J <[email protected]>2020-02-23 14:14:05 +0300
commit9ef9dfed7928e9a96b9545074f8aeb1468fda46c (patch)
treea50850ed8d74cf72964ae755e7e4790c8694a043 /service/reload/service.go
parent6a23ccdcda44ea8d90eb174ce3aab99d6b67b495 (diff)
- need batching
Diffstat (limited to 'service/reload/service.go')
-rw-r--r--service/reload/service.go50
1 files changed, 34 insertions, 16 deletions
diff --git a/service/reload/service.go b/service/reload/service.go
index ab249c41..359b3331 100644
--- a/service/reload/service.go
+++ b/service/reload/service.go
@@ -3,6 +3,7 @@ package reload
import (
"errors"
"fmt"
+ "github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
"os"
@@ -14,17 +15,20 @@ import (
const ID = "reload"
type Service struct {
- reloadConfig *Config
- watcher *Watcher
+ cfg *Config
+ log *logrus.Logger
+ watcher *Watcher
}
// Init controller service
-func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
- s.reloadConfig = cfg
- if !s.reloadConfig.Enabled {
+func (s *Service) Init(cfg *Config, log *logrus.Logger, c service.Container) (bool, error) {
+ if cfg == nil || len(cfg.Services) == 0 {
return false, nil
}
+ s.cfg = cfg
+ s.log = log
+
var configs []WatcherConfig
// mount Services to designated services
@@ -37,7 +41,7 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
}
}
- for serviceName, config := range s.reloadConfig.Services {
+ for serviceName, config := range s.cfg.Services {
if cfg.Services[serviceName].service == nil {
continue
}
@@ -73,25 +77,22 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
}
func (s *Service) Serve() error {
- if !s.reloadConfig.Enabled {
- return nil
- }
-
- if s.reloadConfig.Interval < time.Second {
+ if s.cfg.Interval < time.Second {
return errors.New("reload interval is too fast")
}
go func() {
for e := range s.watcher.Event {
+
println(fmt.Sprintf("[UPDATE] Service: %s, path to file: %s, filename: %s", e.service, e.path, e.info.Name()))
- srv := s.reloadConfig.Services[e.service]
+ srv := s.cfg.Services[e.service]
if srv.service != nil {
- s := *srv.service
- err := s.Server().Reset()
+ sv := *srv.service
+ err := sv.Server().Reset()
if err != nil {
- fmt.Println(err)
+ s.log.Error(err)
}
} else {
s.watcher.mu.Lock()
@@ -101,7 +102,24 @@ func (s *Service) Serve() error {
}
}()
- err := s.watcher.StartPolling(s.reloadConfig.Interval)
+ //go func() {
+ // for {
+ // select {
+ // case <-update:
+ // updated = append(updated, update)
+ // case <-time.Ticker:
+ // updated = updated[0:0]
+ // err := sv.Server().Reset()
+ // s.log.Debugf(
+ // "reload %s, found file changes in %s",
+ // strings.Join(updated, ","),
+ // )
+ // case <-exit:
+ // }
+ // }
+ //}()
+
+ err := s.watcher.StartPolling(s.cfg.Interval)
if err != nil {
return err
}