mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 02:31:33 -04:00
Change the sort order of background jobs to be DESC instead of ASC
In theory, if your instance ever creates more jobs then your system cron can handle, the default background jobs get never executed anymore. Because everytime when the joblist returns the next job it looks for the next ID, however there is always a new next ID, so it will never wrap back to execute the low IDs. But when we change the sort order to be DESC, we make sure that these low IDs are always executed, before the system jumps back up to execute the new IDs.
This commit is contained in:
parent
27d6852b3e
commit
3e1dc64737
2 changed files with 16 additions and 7 deletions
|
|
@ -172,8 +172,8 @@ class JobList implements IJobList {
|
|||
$query = $this->connection->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('jobs')
|
||||
->where($query->expr()->gt('id', $query->createNamedParameter($lastId, IQueryBuilder::PARAM_INT)))
|
||||
->orderBy('id', 'ASC')
|
||||
->where($query->expr()->lt('id', $query->createNamedParameter($lastId, IQueryBuilder::PARAM_INT)))
|
||||
->orderBy('id', 'DESC')
|
||||
->setMaxResults(1);
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
|
@ -187,7 +187,7 @@ class JobList implements IJobList {
|
|||
$query = $this->connection->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('jobs')
|
||||
->orderBy('id', 'ASC')
|
||||
->orderBy('id', 'DESC')
|
||||
->setMaxResults(1);
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
namespace Test\BackgroundJob;
|
||||
|
||||
use OCP\BackgroundJob\IJob;
|
||||
use OCP\IDBConnection;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -28,10 +29,17 @@ class JobList extends TestCase {
|
|||
parent::setUp();
|
||||
|
||||
$connection = \OC::$server->getDatabaseConnection();
|
||||
$this->clearJobsList($connection);
|
||||
$this->config = $this->getMock('\OCP\IConfig');
|
||||
$this->instance = new \OC\BackgroundJob\JobList($connection, $this->config);
|
||||
}
|
||||
|
||||
protected function clearJobsList(IDBConnection $connection) {
|
||||
$query = $connection->getQueryBuilder();
|
||||
$query->delete('jobs');
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
protected function getAllSorted() {
|
||||
$jobs = $this->instance->getAll();
|
||||
|
||||
|
|
@ -149,11 +157,11 @@ class JobList extends TestCase {
|
|||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('backgroundjob', 'lastjob', 0)
|
||||
->will($this->returnValue($savedJob1->getId()));
|
||||
->will($this->returnValue($savedJob2->getId()));
|
||||
|
||||
$nextJob = $this->instance->getNext();
|
||||
|
||||
$this->assertEquals($savedJob2, $nextJob);
|
||||
$this->assertEquals($savedJob1, $nextJob);
|
||||
|
||||
$this->instance->remove($job, 1);
|
||||
$this->instance->remove($job, 2);
|
||||
|
|
@ -166,16 +174,17 @@ class JobList extends TestCase {
|
|||
|
||||
$jobs = $this->getAllSorted();
|
||||
|
||||
$savedJob1 = $jobs[count($jobs) - 2];
|
||||
$savedJob2 = $jobs[count($jobs) - 1];
|
||||
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('backgroundjob', 'lastjob', 0)
|
||||
->will($this->returnValue($savedJob2->getId()));
|
||||
->will($this->returnValue($savedJob1->getId()));
|
||||
|
||||
$nextJob = $this->instance->getNext();
|
||||
|
||||
$this->assertEquals($jobs[0], $nextJob);
|
||||
$this->assertEquals($savedJob2, $nextJob);
|
||||
|
||||
$this->instance->remove($job, 1);
|
||||
$this->instance->remove($job, 2);
|
||||
|
|
|
|||
Loading…
Reference in a new issue