summaryrefslogtreecommitdiff
path: root/watcher.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-05-02 18:51:27 +0300
committerWolfy-J <[email protected]>2019-05-02 18:51:27 +0300
commitbb95a9fbd6cc7e8a2d8204417e965dc8e1282128 (patch)
tree46288a4337701a1ee6c7b8734e31cf531cf558fa /watcher.go
parentb3e7bbccdd7636b6ce7d90cf4f295e498feb719c (diff)
base watcher implementation
Diffstat (limited to 'watcher.go')
-rw-r--r--watcher.go50
1 files changed, 39 insertions, 11 deletions
diff --git a/watcher.go b/watcher.go
index 05b8a659..3b654c34 100644
--- a/watcher.go
+++ b/watcher.go
@@ -1,22 +1,50 @@
package roadrunner
import (
- "sync"
+ "log"
"time"
)
-// Watcher watches for workers.
-type Watcher interface {
- // Keep must return true and nil if worker is OK to continue working,
- // must return false and optional error to force worker destruction.
- Keep(p Pool, w *Worker) (keep bool, err error)
-}
-
// disconnect??
-type LazyWatcher struct {
+type Watcher struct {
// defines how often
interval time.Duration
+ pool Pool
+
+ stop chan interface{}
+}
+
+// NewWatcher creates new pool watcher.
+func NewWatcher(p Pool, i time.Duration) *Watcher {
+ w := &Watcher{
+ interval: i,
+ pool: p,
+ stop: make(chan interface{}),
+ }
+
+ go func() {
+ ticker := time.NewTicker(w.interval)
+
+ for {
+ select {
+ case <-ticker.C:
+ w.update()
+ case <-w.stop:
+ return
+ }
+ }
+ }()
+
+ return w
+}
+
+func (w *Watcher) Stop() {
+ close(w.stop)
+}
+
+func (w *Watcher) update() {
+ for _, w := range w.pool.Workers() {
+ log.Println(w)
- mu sync.Mutex
- p Pool
+ }
}