aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-29 10:02:52 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-29 10:02:52 +0100
commit24908a439a8b17929af57f122bc931e4deaefd01 (patch)
tree7e40bf7f3f77be959f71fb24b74e51e1626b4248
parent4070657875f0d98abf15f3fdcb50a173e9e087ce (diff)
parentc83b3d6a264e4fccda13278b9dd9c02c4e819887 (diff)
downloadnextcloud-server-24908a439a8b17929af57f122bc931e4deaefd01.tar.gz
nextcloud-server-24908a439a8b17929af57f122bc931e4deaefd01.zip
Merge pull request #21987 from owncloud/issue-21980-too-many-job-send-mysql-away
Do not create a loop that generates thousands of jobs
-rw-r--r--cron.php13
-rw-r--r--lib/private/backgroundjob/joblist.php2
-rw-r--r--lib/public/backgroundjob.php38
-rw-r--r--lib/public/backgroundjob/ijoblist.php2
4 files changed, 18 insertions, 37 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
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();