diff options
-rw-r--r-- | cron.php | 13 | ||||
-rw-r--r-- | lib/private/backgroundjob/joblist.php | 2 | ||||
-rw-r--r-- | lib/public/backgroundjob.php | 38 | ||||
-rw-r--r-- | lib/public/backgroundjob/ijoblist.php | 2 |
4 files changed, 18 insertions, 37 deletions
@@ -130,11 +130,20 @@ try { // Work $jobList = \OC::$server->getJobList(); - $jobs = $jobList->getAll(); - foreach ($jobs as $job) { + + $executedJobs = []; + while ($job = $jobList->getNext()) { + if (isset($executedJobs[$job->getId()])) { + break; + } + $logger->debug('Run job with ID ' . $job->getId(), ['app' => 'cron']); $job->execute($jobList, $logger); $logger->debug('Finished job with ID ' . $job->getId(), ['app' => 'cron']); + + $jobList->setLastJob($job); + $executedJobs[$job->getId()] = true; + unset($job); } // unlock the file diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index cc9be574807..2920cb5214c 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -139,6 +139,8 @@ class JobList implements IJobList { * 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. */ public function getAll() { $query = $this->connection->getQueryBuilder(); diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index c8acb7e538b..cc76506758b 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -34,7 +34,6 @@ // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; -use \OC\BackgroundJob\JobList; /** * This class provides functions to register backgroundjobs in ownCloud @@ -115,16 +114,7 @@ class BackgroundJob { * @since 4.5.0 */ static public function allRegularTasks() { - $jobList = \OC::$server->getJobList(); - $allJobs = $jobList->getAll(); - $regularJobs = array(); - foreach ($allJobs as $job) { - if ($job instanceof RegularLegacyJob) { - $key = implode('-', $job->getArgument()); - $regularJobs[$key] = $job->getArgument(); - } - } - return $regularJobs; + return []; } /** @@ -146,17 +136,7 @@ class BackgroundJob { * @since 4.5.0 */ public static function allQueuedTasks() { - $jobList = \OC::$server->getJobList(); - $allJobs = $jobList->getAll(); - $queuedJobs = array(); - foreach ($allJobs as $job) { - if ($job instanceof QueuedLegacyJob) { - $queuedJob = $job->getArgument(); - $queuedJob['id'] = $job->getId(); - $queuedJobs[] = $queuedJob; - } - } - return $queuedJobs; + return []; } /** @@ -167,19 +147,7 @@ class BackgroundJob { * @since 4.5.0 */ public static function queuedTaskWhereAppIs($app) { - $jobList = \OC::$server->getJobList(); - $allJobs = $jobList->getAll(); - $queuedJobs = array(); - foreach ($allJobs as $job) { - if ($job instanceof QueuedLegacyJob) { - $queuedJob = $job->getArgument(); - $queuedJob['id'] = $job->getId(); - if ($queuedJob['app'] === $app) { - $queuedJobs[] = $queuedJob; - } - } - } - return $queuedJobs; + return []; } /** diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php index 13775457edd..5a76ce1ba26 100644 --- a/lib/public/backgroundjob/ijoblist.php +++ b/lib/public/backgroundjob/ijoblist.php @@ -64,6 +64,8 @@ interface IJobList { * * @return \OCP\BackgroundJob\IJob[] * @since 7.0.0 + * @deprecated 9.0.0 - This method is dangerous since it can cause load and + * memory problems when creating too many instances. */ public function getAll(); |