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 | |
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')
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 33 | ||||
-rw-r--r-- | lib/public/BackgroundJob/IJobList.php | 15 |
2 files changed, 44 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(); + } } diff --git a/lib/public/BackgroundJob/IJobList.php b/lib/public/BackgroundJob/IJobList.php index 299d6725229..b8d6b03c6ea 100644 --- a/lib/public/BackgroundJob/IJobList.php +++ b/lib/public/BackgroundJob/IJobList.php @@ -98,6 +98,13 @@ interface IJobList { public function getById($id); /** + * @param int $id + * @return array|null + * @since 22.0.0 + */ + public function getDetailsById(int $id): ?array; + + /** * set the job that was last ran to the current time * * @param \OCP\BackgroundJob\IJob $job @@ -129,4 +136,12 @@ interface IJobList { * @since 12.0.0 */ public function setExecutionTime(IJob $job, $timeTaken); + + /** + * Reset the $job so it executes on the next trigger + * + * @param IJob $job + * @since 22.0.0 + */ + public function resetBackgroundJob(IJob $job): void; } |