]> source.dussan.org Git - nextcloud-server.git/commitdiff
Do not create a loop that generates thousands of jobs
authorJoas Schilling <nickvergessen@owncloud.com>
Thu, 28 Jan 2016 14:34:50 +0000 (15:34 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Thu, 28 Jan 2016 14:40:23 +0000 (15:40 +0100)
cron.php

index afcf47cb0e9cd433c7ee26893059280f9c7148c9..73f233e1350065e49a738cb3163a0e714bd510bf 100644 (file)
--- 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