From 5238fc3f549d4eaddeb18a65493a3d27472c5f70 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 28 Jan 2016 15:34:50 +0100 Subject: [PATCH] Do not create a loop that generates thousands of jobs --- cron.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cron.php b/cron.php index afcf47cb0e9..73f233e1350 100644 --- a/cron.php +++ b/cron.php @@ -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 -- 2.39.5