aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/TaskProcessing/Db
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-05-17 11:54:31 +0200
committerprovokateurin <kate@provokateurin.de>2024-07-01 17:11:12 +0200
commitf5ff8136ac3e26cc6b7676dd1f9d307736ad1918 (patch)
tree9a4121721e4a2fe599897b3090a351a5b72d0844 /lib/private/TaskProcessing/Db
parent5aefdc399eb17a86f3c2b59713ca6448479f99fd (diff)
downloadnextcloud-server-f5ff8136ac3e26cc6b7676dd1f9d307736ad1918.tar.gz
nextcloud-server-f5ff8136ac3e26cc6b7676dd1f9d307736ad1918.zip
feat(TaskProcessingApi): Add endpoint for getting the next task
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'lib/private/TaskProcessing/Db')
-rw-r--r--lib/private/TaskProcessing/Db/TaskMapper.php33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php
index e66c62007cc..86b2a2fcc59 100644
--- a/lib/private/TaskProcessing/Db/TaskMapper.php
+++ b/lib/private/TaskProcessing/Db/TaskMapper.php
@@ -45,21 +45,33 @@ class TaskMapper extends QBMapper {
}
/**
- * @param string|null $taskType
+ * @param list<string> $taskTypes
+ * @param list<int> $taskIdsToIgnore
* @return Task
* @throws DoesNotExistException
* @throws Exception
*/
- public function findOldestScheduledByType(?string $taskType): Task {
+ public function findOldestScheduledByType(array $taskTypes, array $taskIdsToIgnore): Task {
$qb = $this->db->getQueryBuilder();
$qb->select(Task::$columns)
->from($this->tableName)
->where($qb->expr()->eq('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_SCHEDULED, IQueryBuilder::PARAM_INT)))
->setMaxResults(1)
->orderBy('last_updated', 'ASC');
- if ($taskType !== null) {
- $qb->andWhere($qb->expr()->eq('type', $qb->createPositionalParameter($taskType)));
+
+ if (count($taskTypes) > 0) {
+ $filter = $qb->expr()->orX();
+ foreach ($taskTypes as $taskType) {
+ $filter->add($qb->expr()->eq('type', $qb->createPositionalParameter($taskType)));
+ }
+
+ $qb->andWhere($filter);
+ }
+
+ if (count($taskIdsToIgnore) > 0) {
+ $qb->andWhere($qb->expr()->notIn('id', $qb->createNamedParameter($taskIdsToIgnore, IQueryBuilder::PARAM_INT_ARRAY)));
}
+
return $this->findEntity($qb);
}
@@ -140,4 +152,17 @@ class TaskMapper extends QBMapper {
$entity->setLastUpdated($this->timeFactory->now()->getTimestamp());
return parent::update($entity);
}
+
+ public function lockTask(Entity $entity): int {
+ $qb = $this->db->getQueryBuilder();
+ $qb->update($this->tableName)
+ ->set('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_RUNNING, IQueryBuilder::PARAM_INT))
+ ->where($qb->expr()->eq('id', $qb->createPositionalParameter($entity->getId(), IQueryBuilder::PARAM_INT)))
+ ->andWhere($qb->expr()->neq('status', $qb->createPositionalParameter(2, IQueryBuilder::PARAM_INT)));
+ try {
+ return $qb->executeStatement();
+ } catch (Exception) {
+ return 0;
+ }
+ }
}