diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-06-12 09:34:57 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-06-12 10:33:16 +0200 |
commit | 6af99abaa07eec7d6d03597d8940ca3f7cbc6339 (patch) | |
tree | d1ac8fe3330415b945e13ff5efba1c8acc59e58f | |
parent | afeac8f6cb4719de5ef9f4fa7ef85cedaf2d5907 (diff) | |
download | nextcloud-server-fix/cron/log-long-running-jobs-stable26.tar.gz nextcloud-server-fix/cron/log-long-running-jobs-stable26.zip |
fix(cron): Log long running jobsfix/cron/log-long-running-jobs-stable26
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r-- | cron.php | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -149,7 +149,26 @@ try { } $logger->debug('CLI cron call has selected job with ID ' . strval($job->getId()), ['app' => 'cron']); + $timeBefore = time(); $job->execute($jobList, $logger); + $timeAfter = time(); + $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'] + ); + } + // clean up after unclean jobs \OC_Util::tearDownFS(); @@ -159,7 +178,7 @@ try { $executedJobs[$job->getId()] = true; unset($job); - if (time() > $endTime) { + if ($timeAfter > $endTime) { break; } } |