diff options
author | Joas Schilling <coding@schilljs.com> | 2021-05-31 17:15:26 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-10-14 09:57:16 +0200 |
commit | 9cd9f4b4bc87133cf446746295e9730c244b3a49 (patch) | |
tree | 04a08e521e533e61e76f8d2ff3534cf2a6b0db11 /lib/private/BackgroundJob/JobList.php | |
parent | e2a7482b490b6b3e5143b4678d88867a6398b248 (diff) | |
download | nextcloud-server-9cd9f4b4bc87133cf446746295e9730c244b3a49.tar.gz nextcloud-server-9cd9f4b4bc87133cf446746295e9730c244b3a49.zip |
Move queries to the joblist
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/BackgroundJob/JobList.php')
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index f3b96dcbb7b..fe8e94513e1 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -236,19 +236,29 @@ class JobList implements IJobList { * @return IJob|null */ public function getById($id) { + $row = $this->getDetailsById($id); + + if ($row) { + return $this->buildJob($row); + } + + return null; + } + + public function getDetailsById(int $id): ?array { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from('jobs') ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); - $result = $query->execute(); + $result = $query->executeQuery(); $row = $result->fetch(); $result->closeCursor(); if ($row) { - return $this->buildJob($row); - } else { - return null; + return $row; } + + return null; } /** @@ -330,4 +340,19 @@ class JobList implements IJobList { ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); $query->execute(); } + + /** + * Reset the $job so it executes on the next trigger + * + * @param IJob $job + * @since 22.0.0 + */ + public function resetBackgroundJob(IJob $job): void { + $query = $this->connection->getQueryBuilder(); + $query->update('jobs') + ->set('last_run', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)) + ->set('reserved_at', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId()), IQueryBuilder::PARAM_INT)); + $query->executeStatement(); + } } |