|
169 | 169 | $jobDetails = get_class($job) . ' (id: ' . $job->getId() . ', arguments: ' . json_encode($job->getArgument()) . ')'; |
170 | 170 | $logger->debug('CLI cron call has selected job ' . $jobDetails, ['app' => 'cron']); |
171 | 171 |
|
| 172 | + $timeBefore = time(); |
172 | 173 | $memoryBefore = memory_get_usage(); |
173 | 174 | $memoryPeakBefore = memory_get_peak_usage(); |
174 | 175 |
|
175 | 176 | /** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */ |
176 | 177 | $job->execute($jobList); |
177 | 178 |
|
| 179 | + $timeAfter = time(); |
178 | 180 | $memoryAfter = memory_get_usage(); |
179 | 181 | $memoryPeakAfter = memory_get_peak_usage(); |
180 | 182 |
|
| 183 | + $cronInterval = 5 * 60; |
| 184 | + $timeSpent = $timeAfter - $timeBefore; |
| 185 | + if ($timeSpent > $cronInterval) { |
| 186 | + $logLevel = match (true) { |
| 187 | + $timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL, |
| 188 | + $timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR, |
| 189 | + $timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN, |
| 190 | + $timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO, |
| 191 | + default => \OCP\ILogger::DEBUG, |
| 192 | + }; |
| 193 | + $logger->log( |
| 194 | + $logLevel, |
| 195 | + 'Background job ' . $jobDetails . ' ran for ' . $timeSpent . ' seconds', |
| 196 | + ['app' => 'cron'] |
| 197 | + ); |
| 198 | + } |
| 199 | + |
181 | 200 | if ($memoryAfter - $memoryBefore > 10_000_000) { |
182 | 201 | $logger->warning('Used memory grew by more than 10 MB when executing job ' . $jobDetails . ': ' . Util::humanFileSize($memoryAfter). ' (before: ' . Util::humanFileSize($memoryBefore) . ')', ['app' => 'cron']); |
183 | 202 | } |
|
193 | 212 | $executedJobs[$job->getId()] = true; |
194 | 213 | unset($job); |
195 | 214 |
|
196 | | - if (time() > $endTime) { |
| 215 | + if ($timeAfter > $endTime) { |
197 | 216 | break; |
198 | 217 | } |
199 | 218 | } |
|
0 commit comments