summaryrefslogtreecommitdiffstats
path: root/lib/private/BackgroundJob/JobList.php
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-04-20 12:55:06 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-04-23 12:36:12 +0200
commitc01c516323d91bb23f16186ffe0be09b3c412624 (patch)
treefb243da31b49e4eb9b43d322f7fb8eaa688e315e /lib/private/BackgroundJob/JobList.php
parentf4f6431d4d645931bdbac01c86250cae9b27b0e6 (diff)
downloadnextcloud-server-c01c516323d91bb23f16186ffe0be09b3c412624.tar.gz
nextcloud-server-c01c516323d91bb23f16186ffe0be09b3c412624.zip
feat(BackgroundJobs): Allow preventing parallel runs for a job class
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/BackgroundJob/JobList.php')
-rw-r--r--lib/private/BackgroundJob/JobList.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index 67b736b8dd9..6761aa282d1 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -35,6 +35,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\AutoloadNotAllowedException;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
+use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -382,4 +383,21 @@ class JobList implements IJobList {
->where($query->expr()->eq('id', $query->createNamedParameter($job->getId()), IQueryBuilder::PARAM_INT));
$query->executeStatement();
}
+
+ public function hasReservedJob(?string $className): bool {
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')
+ ->from('jobs')
+ ->where($query->expr()->neq('reserved_at', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
+
+ if ($className !== null) {
+ $query->andWhere($query->expr()->eq('class', $query->createNamedParameter($className)));
+ }
+
+ try {
+ return $query->executeQuery()->rowCount() > 0;
+ } catch (Exception $e) {
+ return false;
+ }
+ }
}