mirror of https://github.com/nextcloud/server
feat(bg-jobs): Allow calling cron.php with a background job class
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
8694675a26
commit
52eb6d8726
3
cron.php
3
cron.php
|
@ -160,7 +160,8 @@ try {
|
|||
$endTime = time() + 14 * 60;
|
||||
|
||||
$executedJobs = [];
|
||||
while ($job = $jobList->getNext($onlyTimeSensitive)) {
|
||||
$jobClass = isset($argv[1]) ? $argv[1] : null;
|
||||
while ($job = $jobList->getNext($onlyTimeSensitive, $jobClass)) {
|
||||
if (isset($executedJobs[$job->getId()])) {
|
||||
$jobList->unlockJob($job);
|
||||
break;
|
||||
|
|
|
@ -214,7 +214,7 @@ class JobList implements IJobList {
|
|||
* Get the next job in the list
|
||||
* @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob.
|
||||
*/
|
||||
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
|
||||
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('jobs')
|
||||
|
@ -227,6 +227,10 @@ class JobList implements IJobList {
|
|||
$query->andWhere($query->expr()->eq('time_sensitive', $query->createNamedParameter(IJob::TIME_SENSITIVE, IQueryBuilder::PARAM_INT)));
|
||||
}
|
||||
|
||||
if ($jobClass) {
|
||||
$query->andWhere($query->expr()->eq('class', $query->createNamedParameter($jobClass)));
|
||||
}
|
||||
|
||||
$result = $query->executeQuery();
|
||||
$row = $result->fetch();
|
||||
$result->closeCursor();
|
||||
|
@ -261,7 +265,7 @@ class JobList implements IJobList {
|
|||
|
||||
if ($count === 0) {
|
||||
// Background job already executed elsewhere, try again.
|
||||
return $this->getNext($onlyTimeSensitive);
|
||||
return $this->getNext($onlyTimeSensitive, $jobClass);
|
||||
}
|
||||
|
||||
if ($job === null) {
|
||||
|
@ -274,7 +278,7 @@ class JobList implements IJobList {
|
|||
$reset->executeStatement();
|
||||
|
||||
// Background job from disabled app, try again.
|
||||
return $this->getNext($onlyTimeSensitive);
|
||||
return $this->getNext($onlyTimeSensitive, $jobClass);
|
||||
}
|
||||
|
||||
return $job;
|
||||
|
|
|
@ -100,7 +100,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
|||
/**
|
||||
* get the next job in the list
|
||||
*/
|
||||
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
|
||||
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
|
||||
if (count($this->jobs) > 0) {
|
||||
if ($this->last < (count($this->jobs) - 1)) {
|
||||
$i = $this->last + 1;
|
||||
|
|
Loading…
Reference in New Issue