Skip to content

Commit

Permalink
Merge branch '4.7' into 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Aug 26, 2021
2 parents 6f936a7 + 65555d6 commit 89f00a3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/DataObjects/QueuedJobDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ public function cleanupJob()
}
}

public function onBeforeWrite()
{
// if a job is marked as 'waiting' for a restart, we need to reset the
// worker it was assigned to, otherwise it'll never pick up and go again if
// it was paused from the UI, or a worker stopping to release memory / other reason!
if ($this->JobStatus == QueuedJob::STATUS_WAIT) {
$this->Worker = null;
}

parent::onBeforeWrite();
}

public function onBeforeDelete()
{
parent::onBeforeDelete();
Expand Down
48 changes: 48 additions & 0 deletions tests/QueuedJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,54 @@ public function testNextJob()
$this->assertNotEquals((int) $job->ID, (int) $next->ID);
}

/**
* @throws ValidationException
*/
public function testNextResumedJob()
{
$svc = $this->getService();
$list = $svc->getJobList();

foreach ($list as $job) {
$job->delete();
}

$list = $svc->getJobList();
$this->assertCount(0, $list);

$job = new TestQueuedJob();
$id1 = $svc->queueJob($job);

// okay, lets get the first one and initialise it, then make sure that a subsequent init attempt fails
$job = $svc->getNextPendingJob();

$this->assertEquals($id1, $job->ID);
$svc->testInit($job);

// assign job locking properties
$job->Worker = 'test worker';
$job->WorkerCount = (int) $job->WorkerCount + 1;
$job->Expiry = '2016-01-01 16:00:01';
$job->write();

$next = $svc->getNextPendingJob();

$this->assertNull($next);

// okay now pause the job and resume it - it _should_ be the next one
$job->pause(true);

$next = $svc->getNextPendingJob();
$this->assertNull($next);

$job->resume(true);

$next = $svc->getNextPendingJob();
$this->assertNotNull($next);

$this->assertEquals($job->ID, $next->ID);
}

/**
* Verify that broken jobs are correctly verified for health and restarted as necessary
*
Expand Down

0 comments on commit 89f00a3

Please sign in to comment.