aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2024-06-12 09:34:57 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2024-06-12 10:33:16 +0200
commit6af99abaa07eec7d6d03597d8940ca3f7cbc6339 (patch)
treed1ac8fe3330415b945e13ff5efba1c8acc59e58f
parentafeac8f6cb4719de5ef9f4fa7ef85cedaf2d5907 (diff)
downloadnextcloud-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.php21
1 files changed, 20 insertions, 1 deletions
diff --git a/cron.php b/cron.php
index 7d661621ed0..ce38ad04615 100644
--- a/cron.php
+++ b/cron.php
@@ -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;
}
}