|
|
@ -28,13 +28,14 @@ try { |
|
|
|
Run the background job routine |
|
|
|
Run the background job routine |
|
|
|
|
|
|
|
|
|
|
|
Usage: |
|
|
|
Usage: |
|
|
|
php -f cron.php -- [-h] [<job-classes>...] |
|
|
|
php -f cron.php -- [-h] [--verbose] [<job-classes>...] |
|
|
|
|
|
|
|
|
|
|
|
Arguments: |
|
|
|
Arguments: |
|
|
|
job-classes Optional job class list to only run those jobs |
|
|
|
job-classes Optional job class list to only run those jobs |
|
|
|
|
|
|
|
|
|
|
|
Options: |
|
|
|
Options: |
|
|
|
-h, --help Display this help message' . PHP_EOL; |
|
|
|
-h, --help Display this help message |
|
|
|
|
|
|
|
-v, --verbose Output more information' . PHP_EOL; |
|
|
|
exit(0); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -57,9 +58,10 @@ Options: |
|
|
|
|
|
|
|
|
|
|
|
// load all apps to get all api routes properly setup |
|
|
|
// load all apps to get all api routes properly setup |
|
|
|
Server::get(IAppManager::class)->loadApps(); |
|
|
|
Server::get(IAppManager::class)->loadApps(); |
|
|
|
|
|
|
|
|
|
|
|
Server::get(ISession::class)->close(); |
|
|
|
Server::get(ISession::class)->close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$verbose = isset($argv[1]) && ($argv[1] === '-v' || $argv[1] === '--verbose'); |
|
|
|
|
|
|
|
|
|
|
|
// initialize a dummy memory session |
|
|
|
// initialize a dummy memory session |
|
|
|
$session = new \OC\Session\Memory(); |
|
|
|
$session = new \OC\Session\Memory(); |
|
|
|
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
|
|
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
|
@ -142,7 +144,7 @@ Options: |
|
|
|
|
|
|
|
|
|
|
|
$executedJobs = []; |
|
|
|
$executedJobs = []; |
|
|
|
// a specific job class list can optionally be given as argument |
|
|
|
// a specific job class list can optionally be given as argument |
|
|
|
$jobClasses = array_slice($argv, 1); |
|
|
|
$jobClasses = array_slice($argv, $verbose ? 2 : 1); |
|
|
|
$jobClasses = empty($jobClasses) ? null : $jobClasses; |
|
|
|
$jobClasses = empty($jobClasses) ? null : $jobClasses; |
|
|
|
|
|
|
|
|
|
|
|
while ($job = $jobList->getNext($onlyTimeSensitive, $jobClasses)) { |
|
|
|
while ($job = $jobList->getNext($onlyTimeSensitive, $jobClasses)) { |
|
|
@ -157,6 +159,10 @@ Options: |
|
|
|
$timeBefore = time(); |
|
|
|
$timeBefore = time(); |
|
|
|
$memoryBefore = memory_get_usage(); |
|
|
|
$memoryBefore = memory_get_usage(); |
|
|
|
$memoryPeakBefore = memory_get_peak_usage(); |
|
|
|
$memoryPeakBefore = memory_get_peak_usage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($verbose) { |
|
|
|
|
|
|
|
echo 'Starting job ' . $jobDetails . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */ |
|
|
|
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */ |
|
|
|
$job->execute($jobList); |
|
|
|
$job->execute($jobList); |
|
|
@ -183,16 +189,28 @@ Options: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($memoryAfter - $memoryBefore > 50_000_000) { |
|
|
|
if ($memoryAfter - $memoryBefore > 50_000_000) { |
|
|
|
$logger->warning('Used memory grew by more than 50 MB when executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryAfter). ' (before: ' . Util::humanFileSize($memoryBefore) . ')', ['app' => 'cron']); |
|
|
|
$message = 'Used memory grew by more than 50 MB when executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryAfter). ' (before: ' . Util::humanFileSize($memoryBefore) . ')'; |
|
|
|
|
|
|
|
$logger->warning($message, ['app' => 'cron']); |
|
|
|
|
|
|
|
if ($verbose) { |
|
|
|
|
|
|
|
echo $message . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ($memoryPeakAfter > 300_000_000 && $memoryPeakBefore <= 300_000_000) { |
|
|
|
if ($memoryPeakAfter > 300_000_000 && $memoryPeakBefore <= 300_000_000) { |
|
|
|
$logger->warning('Cron job used more than 300 MB of ram after executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryPeakAfter) . ' (before: ' . Util::humanFileSize($memoryPeakBefore) . ')', ['app' => 'cron']); |
|
|
|
$message = 'Cron job used more than 300 MB of ram after executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryPeakAfter) . ' (before: ' . Util::humanFileSize($memoryPeakBefore) . ')'; |
|
|
|
|
|
|
|
$logger->warning($message, ['app' => 'cron']); |
|
|
|
|
|
|
|
if ($verbose) { |
|
|
|
|
|
|
|
echo $message . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// clean up after unclean jobs |
|
|
|
// clean up after unclean jobs |
|
|
|
Server::get(\OC\Files\SetupManager::class)->tearDown(); |
|
|
|
Server::get(\OC\Files\SetupManager::class)->tearDown(); |
|
|
|
$tempManager->clean(); |
|
|
|
$tempManager->clean(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($verbose) { |
|
|
|
|
|
|
|
echo 'Job ' . $jobDetails . ' done in ' . ($timeAfter - $timeBefore) . ' seconds' . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$jobList->setLastJob($job); |
|
|
|
$jobList->setLastJob($job); |
|
|
|
$executedJobs[$job->getId()] = true; |
|
|
|
$executedJobs[$job->getId()] = true; |
|
|
|
unset($job); |
|
|
|
unset($job); |
|
|
|