aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2024-06-13 18:28:22 +0200
committerGitHub <noreply@github.com>2024-06-13 18:28:22 +0200
commit72453d806cadbc2202165b5cc8f709a5e4422706 (patch)
tree517e8ba3e093a55c6fcf1cc08f562ad967adc296
parent51a695f530e975159e36ed1f4dd6381ce795b2c6 (diff)
parente15d843a2bc3e5a7dc4b822f3cfafa1b321ef09d (diff)
downloadnextcloud-server-72453d806cadbc2202165b5cc8f709a5e4422706.tar.gz
nextcloud-server-72453d806cadbc2202165b5cc8f709a5e4422706.zip
Merge pull request #45855 from nextcloud/backport/45804/stable27
[stable27] fix(cron): Log long running jobs
-rw-r--r--cron.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/cron.php b/cron.php
index 7d661621ed0..b547a0b4e9b 100644
--- a/cron.php
+++ b/cron.php
@@ -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;
}
}