diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-06-12 09:34:57 +0200 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-06-28 15:09:28 +0200 |
commit | 949c386943055d250309a7e8606f7d07da425bca (patch) | |
tree | 9654862932069d758062d5f16b24b5152abf4505 /cron.php | |
parent | faf30177624e958e1472a5abcfb9e9604e855b57 (diff) | |
download | nextcloud-server-949c386943055d250309a7e8606f7d07da425bca.tar.gz nextcloud-server-949c386943055d250309a7e8606f7d07da425bca.zip |
fix(cron): Log long running jobs
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'cron.php')
-rw-r--r-- | cron.php | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -148,8 +148,28 @@ try { break; } + $jobDetails = get_class($job) . ' (id: ' . $job->getId() . ', arguments: ' . json_encode($job->getArgument()) . ')'; $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 +179,7 @@ try { $executedJobs[$job->getId()] = true; unset($job); - if (time() > $endTime) { + if ($timeAfter > $endTime) { break; } } |