diff options
-rwxr-xr-x | .gitignore | 3 | ||||
-rw-r--r-- | plugins/gzip/tests/configs/.rr-http-withGzip.yaml | 2 | ||||
-rw-r--r-- | tests/psr-worker.php (renamed from plugins/gzip/tests/psr-worker.php) | 2 | ||||
-rwxr-xr-x | worker_watcher.go | 32 |
4 files changed, 24 insertions, 15 deletions
@@ -21,5 +21,4 @@ vendor vendor_php builds/ tests/vendor/ -.rr-sample.yaml -psr-worker.php +.rr-sample.yaml
\ No newline at end of file diff --git a/plugins/gzip/tests/configs/.rr-http-withGzip.yaml b/plugins/gzip/tests/configs/.rr-http-withGzip.yaml index b91a9aad..38fdfe47 100644 --- a/plugins/gzip/tests/configs/.rr-http-withGzip.yaml +++ b/plugins/gzip/tests/configs/.rr-http-withGzip.yaml @@ -1,5 +1,5 @@ server: - command: "php psr-worker.php" + command: "php ../../../tests/psr-worker.php" user: "" group: "" env: diff --git a/plugins/gzip/tests/psr-worker.php b/tests/psr-worker.php index ed936bde..b5090d46 100644 --- a/plugins/gzip/tests/psr-worker.php +++ b/tests/psr-worker.php @@ -6,7 +6,7 @@ use Spiral\Goridge; use Spiral\RoadRunner; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../../vendor_php/autoload.php"; +require dirname(__DIR__) . "/vendor/autoload.php"; $worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT)); $psr7 = new RoadRunner\PSR7Client($worker); diff --git a/worker_watcher.go b/worker_watcher.go index 3afb91ca..fa160d57 100755 --- a/worker_watcher.go +++ b/worker_watcher.go @@ -80,6 +80,25 @@ func (stack *Stack) FindAndRemoveByPid(pid int64) bool { return false } +func (stack *Stack) Workers() []WorkerBase { + stack.mutex.Lock() + defer stack.mutex.Unlock() + workersCopy := make([]WorkerBase, 0, 1) + // copy + for _, v := range stack.workers { + sw := v.(SyncWorker) + workersCopy = append(workersCopy, sw) + } + + return workersCopy +} + +func (stack *Stack) isDestroying() bool { + stack.mutex.Lock() + defer stack.mutex.Unlock() + return stack.destroy +} + // we also have to give a chance to pool to Push worker (return it) func (stack *Stack) Destroy(ctx context.Context) { stack.mutex.Lock() @@ -260,7 +279,6 @@ func (ww *workerWatcher) RemoveWorker(wb WorkerBase) error { // O(1) operation func (ww *workerWatcher) PushWorker(w WorkerBase) { - //ww.IncreaseWorkersCount() ww.mutex.Lock() defer ww.mutex.Unlock() ww.stack.Push(w) @@ -268,21 +286,13 @@ func (ww *workerWatcher) PushWorker(w WorkerBase) { // Destroy all underlying stack (but let them to complete the task) func (ww *workerWatcher) Destroy(ctx context.Context) { - // destroy stack + // destroy stack, we don't use ww mutex here, since we should be able to push worker ww.stack.Destroy(ctx) } // Warning, this is O(n) operation, and it will return copy of the actual workers func (ww *workerWatcher) WorkersList() []WorkerBase { - ww.stack.mutex.Lock() - defer ww.stack.mutex.Unlock() - workersCopy := make([]WorkerBase, 0, 1) - for _, v := range ww.stack.workers { - sw := v.(SyncWorker) - workersCopy = append(workersCopy, sw) - } - - return workersCopy + return ww.stack.Workers() } func (ww *workerWatcher) wait(w WorkerBase) { |