diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-10-15 11:09:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 11:09:23 +0200 |
commit | f7a4ff4d633ab9cd964e1f5f71158737e73ed1b7 (patch) | |
tree | f68ef635cd101220e479ac3650813c9616c4350c /lib | |
parent | b6a3ba136c4b69cedd613ceb36244656ae31941c (diff) | |
parent | 3adc997833f046ecddadcf5630a686405aeb69ae (diff) | |
download | nextcloud-server-f7a4ff4d633ab9cd964e1f5f71158737e73ed1b7.tar.gz nextcloud-server-f7a4ff4d633ab9cd964e1f5f71158737e73ed1b7.zip |
Merge pull request #27217 from nextcloud/techdebt/noid/make-debugging-a-cron-job-easier
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 33 | ||||
-rw-r--r-- | lib/public/BackgroundJob/IJobList.php | 15 |
4 files changed, 46 insertions, 4 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 353fc22d486..376324213a9 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -818,6 +818,7 @@ return array( 'OC\\Core\\Command\\Background\\Ajax' => $baseDir . '/core/Command/Background/Ajax.php', 'OC\\Core\\Command\\Background\\Base' => $baseDir . '/core/Command/Background/Base.php', 'OC\\Core\\Command\\Background\\Cron' => $baseDir . '/core/Command/Background/Cron.php', + 'OC\\Core\\Command\\Background\\Job' => $baseDir . '/core/Command/Background/Job.php', 'OC\\Core\\Command\\Background\\WebCron' => $baseDir . '/core/Command/Background/WebCron.php', 'OC\\Core\\Command\\Base' => $baseDir . '/core/Command/Base.php', 'OC\\Core\\Command\\Broadcast\\Test' => $baseDir . '/core/Command/Broadcast/Test.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index f7c541d8c31..7c6d2c9380e 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -847,6 +847,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Command\\Background\\Ajax' => __DIR__ . '/../../..' . '/core/Command/Background/Ajax.php', 'OC\\Core\\Command\\Background\\Base' => __DIR__ . '/../../..' . '/core/Command/Background/Base.php', 'OC\\Core\\Command\\Background\\Cron' => __DIR__ . '/../../..' . '/core/Command/Background/Cron.php', + 'OC\\Core\\Command\\Background\\Job' => __DIR__ . '/../../..' . '/core/Command/Background/Job.php', 'OC\\Core\\Command\\Background\\WebCron' => __DIR__ . '/../../..' . '/core/Command/Background/WebCron.php', 'OC\\Core\\Command\\Base' => __DIR__ . '/../../..' . '/core/Command/Base.php', 'OC\\Core\\Command\\Broadcast\\Test' => __DIR__ . '/../../..' . '/core/Command/Broadcast/Test.php', diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index f3b96dcbb7b..9d8d1d836b6 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 23.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..9f3b485c280 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 23.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 23.0.0 + */ + public function resetBackgroundJob(IJob $job): void; } |