summaryrefslogtreecommitdiff
path: root/service/reload/service.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-02-20 01:02:12 +0300
committerValery Piashchynski <[email protected]>2020-02-20 01:02:12 +0300
commit54fb0dc2baa8d874f0ff090b49c80361bb6a9557 (patch)
treeeb3b00d4aca057206977426cc02abd4f1f35fd17 /service/reload/service.go
parent9cff24e4d515d684cefdf46624da90d22224aeaa (diff)
Update wathcer implementation. Need to rethink structure and optimize
algorithms
Diffstat (limited to 'service/reload/service.go')
-rw-r--r--service/reload/service.go91
1 files changed, 51 insertions, 40 deletions
diff --git a/service/reload/service.go b/service/reload/service.go
index 78f147b7..f50d6626 100644
--- a/service/reload/service.go
+++ b/service/reload/service.go
@@ -3,6 +3,7 @@ package reload
import (
"github.com/spiral/roadrunner/service"
"os"
+ "strings"
"time"
)
@@ -11,7 +12,8 @@ const ID = "reload"
type Service struct {
reloadConfig *Config
- container service.Container
+ container service.Container
+ watcher *Watcher
}
// Init controller service
@@ -23,61 +25,70 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
}
func (s *Service) Serve() error {
- w, err := NewWatcher(SetMaxFileEvents(100))
- if err != nil {
- return err
- }
-
- name , err := os.Getwd()
- if err != nil {
- return err
+ if !s.reloadConfig.Enabled {
+ return nil
}
- err = w.AddSingle(name)
+ var err error
+ s.watcher, err = NewWatcher([]WatcherConfig{WatcherConfig{
+ serviceName: "test",
+ recursive: false,
+ directories: []string{"/service"},
+ filterHooks: func(filename, pattern string) error {
+ if strings.Contains(filename, pattern) {
+ return ErrorSkip
+ }
+ return nil
+ },
+ files: make(map[string]os.FileInfo),
+ //ignored: []string{".php"},
+ }})
if err != nil {
return err
}
- go func() {
- err = w.StartPolling(time.Second)
- if err != nil {
- }
- }()
+ s.watcher.AddSingle("test", "/service")
- // read events and restart corresponding services
-
-
- for {
- select {
- case e := <- w.Event:
- println(e.Name())
+ go func() {
+ for {
+ select {
+ case e := <-s.watcher.Event:
+ println(e.Name())
+ }
}
+ //for e = range w.Event {
+ //
+ // println("event")
+ // // todo use status
+ // //svc, _ := s.container.Get("http")
+ // //if svc != nil {
+ // // if srv, ok := svc.(service.Service); ok {
+ // // srv.Stop()
+ // // err = srv.Serve()
+ // // if err != nil {
+ // // return err
+ // // }
+ // // }
+ // //}
+ //
+ // //println("event skipped due to service is nil")
+ //}
+ }()
+
+ err = s.watcher.StartPolling(time.Second)
+ if err != nil {
+ return err
}
- //for e = range w.Event {
- //
- // println("event")
- // // todo use status
- // //svc, _ := s.container.Get("http")
- // //if svc != nil {
- // // if srv, ok := svc.(service.Service); ok {
- // // srv.Stop()
- // // err = srv.Serve()
- // // if err != nil {
- // // return err
- // // }
- // // }
- // //}
- //
- // //println("event skipped due to service is nil")
- //}
+ // read events and restart corresponding services
return nil
}
func (s *Service) Stop() {
+ //s.watcher.Stop()
-} \ No newline at end of file
+}