summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-01-31 17:56:43 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2022-02-22 10:59:19 +0000
commitc8db7d35bfaeced6536b2794829f3cabd085ff31 (patch)
treedca551b60f8e38ca239efe4bfe5da48b7d2e7999 /lib/private
parent69e73cbdab6ba1c3ad8aab61e801c54accd0cfb9 (diff)
downloadnextcloud-server-c8db7d35bfaeced6536b2794829f3cabd085ff31.tar.gz
nextcloud-server-c8db7d35bfaeced6536b2794829f3cabd085ff31.zip
Allow apps to specify if their background job can be delayed
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/BackgroundJob/JobList.php17
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();
}