optimize code

This commit is contained in:
team2
2026-02-22 19:27:47 +01:00
parent 56617f2612
commit 8c58d6777d
2 changed files with 9 additions and 46 deletions

View File

@@ -240,8 +240,6 @@ final readonly class IngestFlow
*/ */
private function withLock(callable $fn): void private function withLock(callable $fn): void
{ {
$this->lockService->acquire();
try { try {
$fn(); $fn();
} finally { } finally {

View File

@@ -16,14 +16,16 @@ final class IngestOrchestrator
private readonly IngestJobService $jobService, private readonly IngestJobService $jobService,
private readonly EntityManagerInterface $em, private readonly EntityManagerInterface $em,
private readonly IngestFlow $ingestFlow, private readonly IngestFlow $ingestFlow,
) { )
{
} }
public function runForVersion( public function runForVersion(
DocumentVersion $version, DocumentVersion $version,
User $user, User $user,
bool $dryRun = false bool $dryRun = false
): IngestJob { ): IngestJob
{
if (!$this->lockService->acquire()) { if (!$this->lockService->acquire()) {
throw new \RuntimeException('Another ingest job is already running.'); throw new \RuntimeException('Another ingest job is already running.');
@@ -172,41 +174,4 @@ final class IngestOrchestrator
} }
} }
public function runGlobal(User $user, bool $dryRun = false): IngestJob
{
if (!$this->lockService->acquire()) {
throw new \RuntimeException('Another ingest job is already running.');
}
$job = null;
try {
$job = $this->jobService->startJob(
IngestJob::TYPE_GLOBAL_REINDEX,
$user
);
if ($dryRun) {
usleep(200000);
} else {
$this->ingestFlow->globalReindex();
}
$this->jobService->markCompleted($job);
return $job;
} catch (\Throwable $e) {
if ($job) {
$this->jobService->markFailed($job, $e->getMessage());
}
throw $e;
} finally {
$this->lockService->release();
}
}
} }