From 89e57fa5d79e55ab50db2a769f77d7f6c1e295d0 Mon Sep 17 00:00:00 2001 From: Raffael Sahli Date: Thu, 5 Dec 2019 10:01:13 +0100 Subject: [PATCH] fixes (temorarily) message sending failed : Error[22 ] invalid argument --- CHANGELOG.md | 9 +++++++++ src/Worker.php | 4 ++++ src/WorkerManager.php | 2 +- tests/SchedulerTest.php | 16 ++++++++++++++++ tests/WorkerTest.php | 11 +++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97b219d..b09b358 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 3.2.2 +**Maintainer**: Raffael Sahli \ +**Date**: Thu Dec 05 09:38:31 CET 2019 + +### Bugfixes +* Set progress always to 100.0 after a job has been finished +* Fixes build exit worker + + ## 3.2.1 **Maintainer**: Raffael Sahli \ **Date**: Wed Dec 04 09:38:31 CET 2019 diff --git a/src/Worker.php b/src/Worker.php index 2ae740d..8896ebc 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -405,6 +405,10 @@ protected function updateJob(array $job, int $status): bool if ($status >= JobInterface::STATUS_DONE) { $set['ended'] = new UTCDateTime(); + + if(isset($job['progress'])) { + $set['progress'] = 100.0; + } } $result = $this->db->{$this->scheduler->getJobQueue()}->updateMany([ diff --git a/src/WorkerManager.php b/src/WorkerManager.php index c30bb6c..c98bc87 100644 --- a/src/WorkerManager.php +++ b/src/WorkerManager.php @@ -197,7 +197,7 @@ public function exitWorker(int $sig, array $pid): self unset($this->job_map[$id]); } - msg_send($this->queue, WorkerManager::TYPE_WORKER_KILL, [ + @msg_send($this->queue, WorkerManager::TYPE_WORKER_KILL, [ '_id' => $id, 'pid' => $pid['pid'], 'sig' => $sig, diff --git a/tests/SchedulerTest.php b/tests/SchedulerTest.php index b938a53..09a2d32 100644 --- a/tests/SchedulerTest.php +++ b/tests/SchedulerTest.php @@ -263,6 +263,22 @@ public function testUpdateJobProgressRateLimit() $this->assertSame(50.5, $process->getProgress()); } + public function testUpdateJobProgressNoRateLimit() + { + $this->scheduler->setOptions([ + Scheduler::OPTION_PROGRESS_RATE_LIMIT => 0, + ]); + + $process = $this->scheduler->addJob('test', ['foo' => 'bar']); + $job = $this->createMock(JobInterface::class); + $job->method('getId')->willReturn($process->getId()); + + $this->scheduler->updateJobProgress($job, 50.5); + $this->scheduler->updateJobProgress($job, 50.6); + $process = $this->scheduler->getJob($process->getId()); + $this->assertSame(50.6, $process->getProgress()); + } + public function testAddOnceDifferentData() { $first = $this->scheduler->addJobOnce('test', 'foo'); diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php index b9244c4..c1497a7 100644 --- a/tests/WorkerTest.php +++ b/tests/WorkerTest.php @@ -202,6 +202,17 @@ public function testStartWorkerExecutePostponedOverwrittenJob() $this->assertSame(JobInterface::STATUS_DONE, $job->getStatus()); } + public function testSetProgressTo100AfterFinish() + { + $job = $this->scheduler->addJob(SuccessJobMock::class, ['foo' => 'bar']); + $job = (new SuccessJobMock())->setId($job->getId());; + + $this->scheduler->updateJobProgress($job, 50.1); + $this->worker->processOne($job->getId()); + $job = $this->scheduler->getJob($job->getId()); + $this->assertSame($job->getProgress(), 100.0); + } + public function testStartWorkerPostponedJobFromPast() { $job = $this->scheduler->addJob(SuccessJobMock::class, ['foo' => 'bar'], [