diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2024-06-12 12:07:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 12:07:44 +0200 |
commit | 8e3a0499be08cca2be8a16a76a1bf72f91720a5b (patch) | |
tree | 305256b0eb692edcce44a717a23d6b684d39eabc | |
parent | f626476b11c25ab002e95d2c8ae54fc802bdf185 (diff) | |
parent | 7ea6eac7434af728b0efe353e1ed235022e500e8 (diff) | |
download | nextcloud-server-8e3a0499be08cca2be8a16a76a1bf72f91720a5b.tar.gz nextcloud-server-8e3a0499be08cca2be8a16a76a1bf72f91720a5b.zip |
Merge pull request #45804 from nextcloud/fix/cron/log-long-running-jobs
fix(cron): Log long running jobs
-rw-r--r-- | cron.php | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -154,15 +154,34 @@ Options: $jobDetails = get_class($job) . ' (id: ' . $job->getId() . ', arguments: ' . json_encode($job->getArgument()) . ')'; $logger->debug('CLI cron call has selected job ' . $jobDetails, ['app' => 'cron']); + $timeBefore = time(); $memoryBefore = memory_get_usage(); $memoryPeakBefore = memory_get_peak_usage(); /** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */ $job->execute($jobList); + $timeAfter = time(); $memoryAfter = memory_get_usage(); $memoryPeakAfter = memory_get_peak_usage(); + $cronInterval = 5 * 60; + $timeSpent = $timeAfter - $timeBefore; + if ($timeSpent > $cronInterval) { + $logLevel = match (true) { + $timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL, + $timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR, + $timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN, + $timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO, + default => \OCP\ILogger::DEBUG, + }; + $logger->log( + $logLevel, + 'Background job ' . $jobDetails . ' ran for ' . $timeSpent . ' seconds', + ['app' => 'cron'] + ); + } + if ($memoryAfter - $memoryBefore > 10_000_000) { $logger->warning('Used memory grew by more than 10 MB when executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryAfter). ' (before: ' . Util::humanFileSize($memoryBefore) . ')', ['app' => 'cron']); } @@ -178,7 +197,7 @@ Options: $executedJobs[$job->getId()] = true; unset($job); - if (time() > $endTime) { + if ($timeAfter > $endTime) { break; } } |