Skip to content

Commit

Permalink
fix(cron): Log long running jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Jun 13, 2024
1 parent cb63256 commit c73c59d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,26 @@
}

$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();
Expand All @@ -159,7 +178,7 @@
$executedJobs[$job->getId()] = true;
unset($job);

if (time() > $endTime) {
if ($timeAfter > $endTime) {
break;
}
}
Expand Down

0 comments on commit c73c59d

Please sign in to comment.