Skip to content

Commit

Permalink
Merge pull request #35 from gyselroth/dev
Browse files Browse the repository at this point in the history
v3.2.2
  • Loading branch information
raffis authored Dec 5, 2019
2 parents 456d9ef + 89e57fa commit db72650
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.2.2
**Maintainer**: Raffael Sahli <[email protected]>\
**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 <[email protected]>\
**Date**: Wed Dec 04 09:38:31 CET 2019
Expand Down
4 changes: 4 additions & 0 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion src/WorkerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions tests/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 11 additions & 0 deletions tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], [
Expand Down

0 comments on commit db72650

Please sign in to comment.