diff options
author | Wolfy-J <[email protected]> | 2019-05-02 18:51:27 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-05-02 18:51:27 +0300 |
commit | bb95a9fbd6cc7e8a2d8204417e965dc8e1282128 (patch) | |
tree | 46288a4337701a1ee6c7b8734e31cf531cf558fa /watcher.go | |
parent | b3e7bbccdd7636b6ce7d90cf4f295e498feb719c (diff) |
base watcher implementation
Diffstat (limited to 'watcher.go')
-rw-r--r-- | watcher.go | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -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 + } } |