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