diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index cece8bdf900..16dfa7b58a6 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -184,9 +184,10 @@ class JobList implements IJobList { /** * get the next job in the list * + * @param bool $onlyTimeSensitive * @return IJob|null */ - public function getNext() { + public function getNext(bool $onlyTimeSensitive = true): ?IJob { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from('jobs') @@ -195,6 +196,10 @@ class JobList implements IJobList { ->orderBy('last_checked', 'ASC') ->setMaxResults(1); + if ($onlyTimeSensitive) { + $query->andWhere($query->expr()->eq('time_sensitive', $query->createNamedParameter(IJob::TIME_SENSITIVE, IQueryBuilder::PARAM_INT))); + } + $update = $this->connection->getQueryBuilder(); $update->update('jobs') ->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime())) @@ -215,7 +220,7 @@ class JobList implements IJobList { if ($count === 0) { // Background job already executed elsewhere, try again. - return $this->getNext(); + return $this->getNext($onlyTimeSensitive); } $job = $this->buildJob($row); @@ -229,7 +234,7 @@ class JobList implements IJobList { $reset->execute(); // Background job from disabled app, try again. - return $this->getNext(); + return $this->getNext($onlyTimeSensitive); } return $job; @@ -333,6 +338,12 @@ class JobList implements IJobList { $query->update('jobs') ->set('last_run', $query->createNamedParameter(time(), IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); + + if ($job instanceof \OCP\BackgroundJob\TimedJob + && !$job->isTimeSensitive()) { + $query->set('time_sensitive', $query->createNamedParameter(IJob::TIME_INSENSITIVE)); + } + $query->execute(); } |