Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(cron): Log long running jobs
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Jun 13, 2024
commit e15d843a2bc3e5a7dc4b822f3cfafa1b321ef09d
22 changes: 21 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,28 @@
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();
Expand All @@ -159,7 +179,7 @@
$executedJobs[$job->getId()] = true;
unset($job);

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