|
13 | 13 |
|
14 | 14 | use OC; |
15 | 15 | use OC\Authentication\LoginCredentials\Store; |
| 16 | +use OC\BackgroundJob\JobClassesRegistry; |
16 | 17 | use OC\DB\Connection; |
17 | 18 | use OC\Security\CSRF\TokenStorage\SessionStorage; |
18 | 19 | use OC\Session\CryptoWrapper; |
|
21 | 22 | use OCP\App\IAppManager; |
22 | 23 | use OCP\BackgroundJob\IJob; |
23 | 24 | use OCP\BackgroundJob\IJobList; |
| 25 | +use OCP\BackgroundJob\IJobRuns; |
24 | 26 | use OCP\Files\ISetupManager; |
25 | 27 | use OCP\IAppConfig; |
26 | 28 | use OCP\IConfig; |
@@ -49,6 +51,8 @@ public function __construct( |
49 | 51 | private readonly ITempManager $tempManager, |
50 | 52 | private readonly IAppConfig $appConfig, |
51 | 53 | private readonly IJobList $jobList, |
| 54 | + private readonly IJobRuns $jobRuns, |
| 55 | + private readonly JobClassesRegistry $jobClassesRegistry, |
52 | 56 | private readonly ISetupManager $setupManager, |
53 | 57 | private readonly bool $isCLI, |
54 | 58 | ) { |
@@ -185,20 +189,27 @@ private function runCli(string $appMode, ?array $jobClasses): void { |
185 | 189 | break; |
186 | 190 | } |
187 | 191 |
|
188 | | - $jobDetails = get_class($job) . ' (id: ' . $job->getId() . ', arguments: ' . json_encode($job->getArgument()) . ')'; |
| 192 | + $jobClass = get_class($job); |
| 193 | + $jobDetails = $jobClass . ' (id: ' . $job->getId() . ', arguments: ' . json_encode($job->getArgument()) . ')'; |
189 | 194 | $this->logger->debug('CLI cron call has selected job ' . $jobDetails, ['app' => 'cron']); |
190 | 195 |
|
191 | 196 | $this->verboseOutput('Starting job ' . $jobDetails); |
192 | 197 |
|
193 | | - $startTime = microtime(true); |
194 | 198 | $referenceMemory = memory_get_usage(); |
195 | 199 | memory_reset_peak_usage(); |
196 | 200 |
|
| 201 | + $jobClassId = $this->jobClassesRegistry->getId($jobClass); |
| 202 | + $jobRunId = $this->jobRuns->started($jobClassId); |
| 203 | + $startTime = microtime(true); |
197 | 204 | $job->start($this->jobList); |
198 | 205 |
|
199 | 206 | $memoryIncrease = memory_get_usage() - $referenceMemory; |
200 | 207 | $timeSpent = microtime(true) - $startTime; |
201 | | - $jobMemoryPeak = memory_get_peak_usage() - $referenceMemory; |
| 208 | + $jobMemoryPeak = memory_get_peak_usage(); |
| 209 | + // TODO Job failure will never be catched here because exceptions are catched within $job->start method |
| 210 | + // The error will only be visible in server logs. |
| 211 | + // It should be a temporary state until a proper job runner is implemented. |
| 212 | + $this->jobRuns->finished($jobRunId, (int)($timeSpent * 1000), (int)($jobMemoryPeak / 1024)); |
202 | 213 |
|
203 | 214 | $cronInterval = 5 * 60; |
204 | 215 | if ($timeSpent > $cronInterval) { |
|
0 commit comments