Merge pull request #21987 from owncloud/issue-21980-too-many-job-send-mysql-away
Do not create a loop that generates thousands of jobs
This commit is contained in:
commit
24908a439a
13
cron.php
13
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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue