diff options
author | Josh <josh.t.richards@gmail.com> | 2024-06-12 16:57:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 16:57:21 -0400 |
commit | ecef3922317cc28e6d34c609e266b68159c2146e (patch) | |
tree | 7cbdc96f6e9f76f815ab0caa9153a0cd49a3ad34 /cron.php | |
parent | 8ee070cce5491a8f6a93354f0239d9747c2635ed (diff) | |
parent | b3e4270135d5de64b2b4d43b3d08f00c91b7beab (diff) | |
download | nextcloud-server-ecef3922317cc28e6d34c609e266b68159c2146e.tar.gz nextcloud-server-ecef3922317cc28e6d34c609e266b68159c2146e.zip |
Merge branch 'master' into jtr/fix-cron-memory-usage-levels
Signed-off-by: Josh <josh.t.richards@gmail.com>
Diffstat (limited to 'cron.php')
-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 > 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']); } @@ -178,7 +197,7 @@ Options: $executedJobs[$job->getId()] = true; unset($job); - if (time() > $endTime) { + if ($timeAfter > $endTime) { break; } } |