From 0e060dad954fc1be9e3866f9b81a7a537d3cc33d Mon Sep 17 00:00:00 2001 From: Max Furtuna Date: Tue, 11 Dec 2018 11:48:25 +0200 Subject: [PATCH] #64 some progress --- lib/Context/Thread.php | 3 +-- lib/Worker/TaskWorker.php | 6 ++++-- lib/Worker/Worker.php | 2 +- test/Worker/AbstractWorkerTest.php | 10 ++++++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Context/Thread.php b/lib/Context/Thread.php index af14ba5b..4beddbe2 100644 --- a/lib/Context/Thread.php +++ b/lib/Context/Thread.php @@ -193,7 +193,6 @@ public function kill() } finally { $this->close(); } - $this->oid = 0; } } @@ -249,7 +248,7 @@ public function join(): Promise Loop::disable($this->watcher); $this->close(); } - $this->oid = 0; + return $response->getResult(); }); } diff --git a/lib/Worker/TaskWorker.php b/lib/Worker/TaskWorker.php index 799185b3..72f9a91b 100644 --- a/lib/Worker/TaskWorker.php +++ b/lib/Worker/TaskWorker.php @@ -155,11 +155,13 @@ public function restart($force = false): Promise { return call(function () use ($force) { if ($force) { - $this->context->kill(); + $this->kill(); } else { yield $this->shutdown(); } - yield $this->context->start(); + + $context = yield $this->context->restart($force); + return new static($context); }); } } diff --git a/lib/Worker/Worker.php b/lib/Worker/Worker.php index 9ccdb7c9..2c9bdc50 100644 --- a/lib/Worker/Worker.php +++ b/lib/Worker/Worker.php @@ -45,7 +45,7 @@ public function kill(); /** * Restart worker. * @param bool $force Whether for cancel current task or wait it finished - * @return Promise + * @return Promise New created worker */ public function restart($force = false): Promise; } diff --git a/test/Worker/AbstractWorkerTest.php b/test/Worker/AbstractWorkerTest.php index d18b1c06..7aab3b01 100644 --- a/test/Worker/AbstractWorkerTest.php +++ b/test/Worker/AbstractWorkerTest.php @@ -267,12 +267,13 @@ public function run(Environment $environment) public function testRestart() { Loop::run(function () { - $worker = $this->createWorker(); + $worker = $original = $this->createWorker(); for ($i=0; $i<=1; $i++) { $returnValue = yield $worker->enqueue(new TestTask(42)); $this->assertEquals(42, $returnValue); - yield $worker->restart(); + $worker = yield $worker->restart(); + $this->assertNotEquals($worker, $original); } }); } @@ -280,12 +281,13 @@ public function testRestart() public function testForceRestart() { Loop::run(function () { - $worker = $this->createWorker(); + $worker = $original = $this->createWorker(); for ($i=0; $i<=1; $i++) { $returnValue = yield $worker->enqueue(new TestTask(42)); $this->assertEquals(42, $returnValue); - yield $worker->restart(true); + $worker = yield $worker->restart(true); + $this->assertNotEquals($worker, $original); } }); }