diff options
Diffstat (limited to 'lib/private/BackgroundJob')
-rw-r--r-- | lib/private/BackgroundJob/Job.php | 92 | ||||
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 416 | ||||
-rw-r--r-- | lib/private/BackgroundJob/Legacy/QueuedJob.php | 36 | ||||
-rw-r--r-- | lib/private/BackgroundJob/Legacy/RegularJob.php | 39 | ||||
-rw-r--r-- | lib/private/BackgroundJob/QueuedJob.php | 48 | ||||
-rw-r--r-- | lib/private/BackgroundJob/TimedJob.php | 62 |
6 files changed, 268 insertions, 425 deletions
diff --git a/lib/private/BackgroundJob/Job.php b/lib/private/BackgroundJob/Job.php deleted file mode 100644 index 312ec628e0b..00000000000 --- a/lib/private/BackgroundJob/Job.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in> - * @author Robin Appelman <robin@icewind.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\BackgroundJob; - -use OCP\BackgroundJob\IJob; -use OCP\BackgroundJob\IJobList; -use OCP\ILogger; - -abstract class Job implements IJob { - /** @var int */ - protected $id; - - /** @var int */ - protected $lastRun; - - /** @var mixed */ - protected $argument; - - public function execute(IJobList $jobList, ILogger $logger = null) { - $jobList->setLastRun($this); - if ($logger === null) { - $logger = \OC::$server->getLogger(); - } - - try { - $jobStartTime = time(); - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); - $this->run($this->argument); - $timeTaken = time() - $jobStartTime; - - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); - $jobList->setExecutionTime($this, $timeTaken); - } catch (\Throwable $e) { - if ($logger) { - $logger->logException($e, [ - 'app' => 'core', - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' - ]); - } - } - } - - abstract protected function run($argument); - - public function setId(int $id) { - $this->id = $id; - } - - public function setLastRun(int $lastRun) { - $this->lastRun = $lastRun; - } - - public function setArgument($argument) { - $this->argument = $argument; - } - - public function getId() { - return $this->id; - } - - public function getLastRun() { - return $this->lastRun; - } - - public function getArgument() { - return $this->argument; - } -} diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 5a89dcdeba6..c00a51e3851 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -1,33 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\BackgroundJob; use OCP\AppFramework\QueryException; @@ -35,152 +12,167 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\AutoloadNotAllowedException; use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\IParallelAwareJob; +use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; +use Psr\Log\LoggerInterface; +use function get_class; +use function json_encode; +use function min; +use function strlen; class JobList implements IJobList { + /** @var array<string, int> */ + protected array $alreadyVisitedParallelBlocked = []; + + public function __construct( + protected IDBConnection $connection, + protected IConfig $config, + protected ITimeFactory $timeFactory, + protected LoggerInterface $logger, + ) { + } - /** @var IDBConnection */ - protected $connection; - - /**@var IConfig */ - protected $config; + public function add($job, $argument = null, ?int $firstCheck = null): void { + if ($firstCheck === null) { + $firstCheck = $this->timeFactory->getTime(); + } - /**@var ITimeFactory */ - protected $timeFactory; + $class = ($job instanceof IJob) ? get_class($job) : $job; - /** - * @param IDBConnection $connection - * @param IConfig $config - * @param ITimeFactory $timeFactory - */ - public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory) { - $this->connection = $connection; - $this->config = $config; - $this->timeFactory = $timeFactory; - } + $argumentJson = json_encode($argument); + if (strlen($argumentJson) > 4000) { + throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)'); + } - /** - * @param IJob|string $job - * @param mixed $argument - */ - public function add($job, $argument = null) { + $query = $this->connection->getQueryBuilder(); if (!$this->has($job, $argument)) { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } - - $argument = json_encode($argument); - if (strlen($argument) > 4000) { - throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)'); - } - - $query = $this->connection->getQueryBuilder(); $query->insert('jobs') ->values([ 'class' => $query->createNamedParameter($class), - 'argument' => $query->createNamedParameter($argument), + 'argument' => $query->createNamedParameter($argumentJson), + 'argument_hash' => $query->createNamedParameter(hash('sha256', $argumentJson)), 'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT), - 'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT), + 'last_checked' => $query->createNamedParameter($firstCheck, IQueryBuilder::PARAM_INT), ]); - $query->execute(); + } else { + $query->update('jobs') + ->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT)) + ->set('last_checked', $query->createNamedParameter($firstCheck, IQueryBuilder::PARAM_INT)) + ->set('last_run', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('class', $query->createNamedParameter($class))) + ->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(hash('sha256', $argumentJson)))); } + $query->executeStatement(); + } + + public function scheduleAfter(string $job, int $runAfter, $argument = null): void { + $this->add($job, $argument, $runAfter); } /** * @param IJob|string $job * @param mixed $argument */ - public function remove($job, $argument = null) { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + public function remove($job, $argument = null): void { + $class = ($job instanceof IJob) ? get_class($job) : $job; $query = $this->connection->getQueryBuilder(); $query->delete('jobs') ->where($query->expr()->eq('class', $query->createNamedParameter($class))); if (!is_null($argument)) { - $argument = json_encode($argument); - $query->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument))); + $argumentJson = json_encode($argument); + $query->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(hash('sha256', $argumentJson)))); + } + + // Add galera safe delete chunking if using mysql + // Stops us hitting wsrep_max_ws_rows when large row counts are deleted + if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) { + // Then use chunked delete + $max = IQueryBuilder::MAX_ROW_DELETION; + + $query->setMaxResults($max); + + do { + $deleted = $query->executeStatement(); + } while ($deleted === $max); + } else { + // Dont use chunked delete - let the DB handle the large row count natively + $query->executeStatement(); } - $query->execute(); } - /** - * @param int $id - */ - protected function removeById($id) { + public function removeById(int $id): void { $query = $this->connection->getQueryBuilder(); $query->delete('jobs') ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); - $query->execute(); + $query->executeStatement(); } /** * check if a job is in the list * - * @param IJob|string $job + * @param IJob|class-string<IJob> $job * @param mixed $argument - * @return bool */ - public function has($job, $argument) { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + public function has($job, $argument): bool { + $class = ($job instanceof IJob) ? get_class($job) : $job; $argument = json_encode($argument); $query = $this->connection->getQueryBuilder(); $query->select('id') ->from('jobs') ->where($query->expr()->eq('class', $query->createNamedParameter($class))) - ->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument))) + ->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(hash('sha256', $argument)))) ->setMaxResults(1); - $result = $query->execute(); + $result = $query->executeQuery(); $row = $result->fetch(); $result->closeCursor(); - return (bool) $row; + return (bool)$row; + } + + public function getJobs($job, ?int $limit, int $offset): array { + $iterable = $this->getJobsIterator($job, $limit, $offset); + return (is_array($iterable)) + ? $iterable + : iterator_to_array($iterable); } /** - * get all jobs in the list - * - * @return IJob[] - * @deprecated 9.0.0 - This method is dangerous since it can cause load and - * memory problems when creating too many instances. + * @param IJob|class-string<IJob>|null $job + * @return iterable<IJob> Avoid to store these objects as they may share a Singleton instance. You should instead use these IJobs instances while looping on the iterable. */ - public function getAll() { + public function getJobsIterator($job, ?int $limit, int $offset): iterable { $query = $this->connection->getQueryBuilder(); $query->select('*') - ->from('jobs'); - $result = $query->execute(); + ->from('jobs') + ->setMaxResults($limit) + ->setFirstResult($offset); + + if ($job !== null) { + $class = ($job instanceof IJob) ? get_class($job) : $job; + $query->where($query->expr()->eq('class', $query->createNamedParameter($class))); + } + + $result = $query->executeQuery(); - $jobs = []; while ($row = $result->fetch()) { $job = $this->buildJob($row); if ($job) { - $jobs[] = $job; + yield $job; } } $result->closeCursor(); - - return $jobs; } /** - * get the next job in the list - * - * @return IJob|null + * @inheritDoc */ - public function getNext() { + public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from('jobs') @@ -189,29 +181,84 @@ class JobList implements IJobList { ->orderBy('last_checked', 'ASC') ->setMaxResults(1); - $update = $this->connection->getQueryBuilder(); - $update->update('jobs') - ->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime())) - ->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime())) - ->where($update->expr()->eq('id', $update->createParameter('jobid'))) - ->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at'))) - ->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked'))); + if ($onlyTimeSensitive) { + $query->andWhere($query->expr()->eq('time_sensitive', $query->createNamedParameter(IJob::TIME_SENSITIVE, IQueryBuilder::PARAM_INT))); + } - $result = $query->execute(); + if (!empty($jobClasses)) { + $orClasses = []; + foreach ($jobClasses as $jobClass) { + $orClasses[] = $query->expr()->eq('class', $query->createNamedParameter($jobClass, IQueryBuilder::PARAM_STR)); + } + $query->andWhere($query->expr()->orX(...$orClasses)); + } + + $result = $query->executeQuery(); $row = $result->fetch(); $result->closeCursor(); if ($row) { + $job = $this->buildJob($row); + + if ($job instanceof IParallelAwareJob && !$job->getAllowParallelRuns() && $this->hasReservedJob(get_class($job))) { + if (!isset($this->alreadyVisitedParallelBlocked[get_class($job)])) { + $this->alreadyVisitedParallelBlocked[get_class($job)] = $job->getId(); + } elseif ($this->alreadyVisitedParallelBlocked[get_class($job)] === $job->getId()) { + $this->logger->info('Skipped through all jobs and revisited a IParallelAwareJob blocked job again, giving up.', ['app' => 'cron']); + return null; + } + $this->logger->info('Skipping ' . get_class($job) . ' job with ID ' . $job->getId() . ' because another job with the same class is already running', ['app' => 'cron']); + + $update = $this->connection->getQueryBuilder(); + $update->update('jobs') + ->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime() + 1)) + ->where($update->expr()->eq('id', $update->createParameter('jobid'))); + $update->setParameter('jobid', $row['id']); + $update->executeStatement(); + + return $this->getNext($onlyTimeSensitive, $jobClasses); + } + + if ($job !== null && isset($this->alreadyVisitedParallelBlocked[get_class($job)])) { + unset($this->alreadyVisitedParallelBlocked[get_class($job)]); + } + + if ($job instanceof \OCP\BackgroundJob\TimedJob) { + $now = $this->timeFactory->getTime(); + $nextPossibleRun = $job->getLastRun() + $job->getInterval(); + if ($now < $nextPossibleRun) { + // This job is not ready for execution yet. Set timestamps to the future to avoid + // re-checking with every cron run. + // To avoid bugs that lead to jobs never executing again, the future timestamp is + // capped at two days. + $nextCheck = min($nextPossibleRun, $now + 48 * 3600); + $updateTimedJob = $this->connection->getQueryBuilder(); + $updateTimedJob->update('jobs') + ->set('last_checked', $updateTimedJob->createNamedParameter($nextCheck, IQueryBuilder::PARAM_INT)) + ->where($updateTimedJob->expr()->eq('id', $updateTimedJob->createParameter('jobid'))); + $updateTimedJob->setParameter('jobid', $row['id']); + $updateTimedJob->executeStatement(); + + return $this->getNext($onlyTimeSensitive, $jobClasses); + } + } + + $update = $this->connection->getQueryBuilder(); + $update->update('jobs') + ->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime())) + ->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime())) + ->where($update->expr()->eq('id', $update->createParameter('jobid'))) + ->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at'))) + ->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked'))); $update->setParameter('jobid', $row['id']); $update->setParameter('reserved_at', $row['reserved_at']); $update->setParameter('last_checked', $row['last_checked']); - $count = $update->execute(); + $count = $update->executeStatement(); if ($count === 0) { // Background job already executed elsewhere, try again. - return $this->getNext(); + return $this->getNext($onlyTimeSensitive, $jobClasses); } - $job = $this->buildJob($row); if ($job === null) { // set the last_checked to 12h in the future to not check failing jobs all over again @@ -220,10 +267,10 @@ class JobList implements IJobList { ->set('reserved_at', $reset->expr()->literal(0, IQueryBuilder::PARAM_INT)) ->set('last_checked', $reset->createNamedParameter($this->timeFactory->getTime() + 12 * 3600, IQueryBuilder::PARAM_INT)) ->where($reset->expr()->eq('id', $reset->createNamedParameter($row['id'], IQueryBuilder::PARAM_INT))); - $reset->execute(); + $reset->executeStatement(); // Background job from disabled app, try again. - return $this->getNext(); + return $this->getNext($onlyTimeSensitive, $jobClasses); } return $job; @@ -233,49 +280,64 @@ class JobList implements IJobList { } /** - * @param int $id - * @return IJob|null + * @return ?IJob The job matching the id. Beware that this object may be a singleton and may be modified by the next call to buildJob. */ - public function getById($id) { + public function getById(int $id): ?IJob { + $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; } /** * get the job object from a row in the db * - * @param array $row - * @return IJob|null + * @param array{class:class-string<IJob>, id:mixed, last_run:mixed, argument:string} $row + * @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob. */ - private function buildJob($row) { + private function buildJob(array $row): ?IJob { try { try { // Try to load the job as a service /** @var IJob $job */ - $job = \OC::$server->query($row['class']); + $job = \OCP\Server::get($row['class']); } catch (QueryException $e) { if (class_exists($row['class'])) { $class = $row['class']; $job = new $class(); } else { - // job from disabled app or old version of an app, no need to do anything + $this->logger->warning('failed to create instance of background job: ' . $row['class'], ['app' => 'cron', 'exception' => $e]); + // Remove job from disabled app or old version of an app + $this->removeById($row['id']); return null; } } - $job->setId((int) $row['id']); - $job->setLastRun((int) $row['last_run']); + if (!($job instanceof IJob)) { + // This most likely means an invalid job was enqueued. We can ignore it. + return null; + } + $job->setId((int)$row['id']); + $job->setLastRun((int)$row['last_run']); $job->setArgument(json_decode($row['argument'], true)); return $job; } catch (AutoloadNotAllowedException $e) { @@ -286,49 +348,107 @@ class JobList implements IJobList { /** * set the job that was last ran - * - * @param IJob $job */ - public function setLastJob(IJob $job) { + public function setLastJob(IJob $job): void { $this->unlockJob($job); - $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId()); + $this->config->setAppValue('backgroundjob', 'lastjob', (string)$job->getId()); } /** * Remove the reservation for a job - * - * @param IJob $job */ - public function unlockJob(IJob $job) { + public function unlockJob(IJob $job): void { $query = $this->connection->getQueryBuilder(); $query->update('jobs') ->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); - $query->execute(); + $query->executeStatement(); } /** * set the lastRun of $job to now - * - * @param IJob $job */ - public function setLastRun(IJob $job) { + public function setLastRun(IJob $job): void { $query = $this->connection->getQueryBuilder(); $query->update('jobs') ->set('last_run', $query->createNamedParameter(time(), IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); - $query->execute(); + + if ($job instanceof \OCP\BackgroundJob\TimedJob + && !$job->isTimeSensitive()) { + $query->set('time_sensitive', $query->createNamedParameter(IJob::TIME_INSENSITIVE)); + } + + $query->executeStatement(); } /** - * @param IJob $job - * @param $timeTaken + * @param int $timeTaken */ - public function setExecutionTime(IJob $job, $timeTaken) { + public function setExecutionTime(IJob $job, $timeTaken): void { $query = $this->connection->getQueryBuilder(); $query->update('jobs') ->set('execution_duration', $query->createNamedParameter($timeTaken, 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->execute(); + $query->executeStatement(); + } + + /** + * Reset the $job so it executes on the next trigger + * + * @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(); + } + + public function hasReservedJob(?string $className = null): bool { + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->where($query->expr()->gt('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - 6 * 3600, IQueryBuilder::PARAM_INT))) + ->setMaxResults(1); + + if ($className !== null) { + $query->andWhere($query->expr()->eq('class', $query->createNamedParameter($className))); + } + + try { + $result = $query->executeQuery(); + $hasReservedJobs = $result->fetch() !== false; + $result->closeCursor(); + return $hasReservedJobs; + } catch (Exception $e) { + $this->logger->debug('Querying reserved jobs failed', ['exception' => $e]); + return false; + } + } + + public function countByClass(): array { + $query = $this->connection->getQueryBuilder(); + $query->select('class') + ->selectAlias($query->func()->count('id'), 'count') + ->from('jobs') + ->orderBy('count') + ->groupBy('class'); + + $result = $query->executeQuery(); + + $jobs = []; + + while (($row = $result->fetch()) !== false) { + /** + * @var array{count:int, class:class-string} $row + */ + $jobs[] = $row; + } + + return $jobs; } } diff --git a/lib/private/BackgroundJob/Legacy/QueuedJob.php b/lib/private/BackgroundJob/Legacy/QueuedJob.php deleted file mode 100644 index 9adaeff89ec..00000000000 --- a/lib/private/BackgroundJob/Legacy/QueuedJob.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\BackgroundJob\Legacy; - -class QueuedJob extends \OC\BackgroundJob\QueuedJob { - public function run($argument) { - $class = $argument['klass']; - $method = $argument['method']; - $parameters = $argument['parameters']; - if (is_callable([$class, $method])) { - call_user_func([$class, $method], $parameters); - } - } -} diff --git a/lib/private/BackgroundJob/Legacy/RegularJob.php b/lib/private/BackgroundJob/Legacy/RegularJob.php deleted file mode 100644 index 95ad8a4ed63..00000000000 --- a/lib/private/BackgroundJob/Legacy/RegularJob.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\BackgroundJob\Legacy; - -use OCP\AutoloadNotAllowedException; - -class RegularJob extends \OC\BackgroundJob\Job { - public function run($argument) { - try { - if (is_callable($argument)) { - call_user_func($argument); - } - } catch (AutoloadNotAllowedException $e) { - // job is from a disabled app, ignore - return null; - } - } -} diff --git a/lib/private/BackgroundJob/QueuedJob.php b/lib/private/BackgroundJob/QueuedJob.php deleted file mode 100644 index 6f10ee4408d..00000000000 --- a/lib/private/BackgroundJob/QueuedJob.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\BackgroundJob; - -use OCP\ILogger; - -/** - * Class QueuedJob - * - * create a background job that is to be executed once - * - * @package OC\BackgroundJob - */ -abstract class QueuedJob extends Job { - /** - * run the job, then remove it from the joblist - * - * @param JobList $jobList - * @param ILogger|null $logger - */ - public function execute($jobList, ILogger $logger = null) { - $jobList->remove($this, $this->argument); - parent::execute($jobList, $logger); - } -} diff --git a/lib/private/BackgroundJob/TimedJob.php b/lib/private/BackgroundJob/TimedJob.php deleted file mode 100644 index c0ce130c6cf..00000000000 --- a/lib/private/BackgroundJob/TimedJob.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\BackgroundJob; - -use OCP\BackgroundJob\IJobList; -use OCP\ILogger; - -/** - * Class QueuedJob - * - * create a background job that is to be executed at an interval - * - * @package OC\BackgroundJob - */ -abstract class TimedJob extends Job { - protected $interval = 0; - - /** - * set the interval for the job - * - * @param int $interval - */ - public function setInterval($interval) { - $this->interval = $interval; - } - - /** - * run the job if - * - * @param IJobList $jobList - * @param ILogger|null $logger - */ - public function execute($jobList, ILogger $logger = null) { - if ((time() - $this->lastRun) > $this->interval) { - parent::execute($jobList, $logger); - } - } -} |