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

@@ -12,18 +12,20 @@ use Symfony\Component\Uid\Uuid;
final class IngestOrchestrator
{
public function __construct(
private readonly LockService $lockService,
private readonly IngestJobService $jobService,
private readonly LockService $lockService,
private readonly IngestJobService $jobService,
private readonly EntityManagerInterface $em,
private readonly IngestFlow $ingestFlow,
) {
private readonly IngestFlow $ingestFlow,
)
{
}
public function runForVersion(
DocumentVersion $version,
User $user,
bool $dryRun = false
): IngestJob {
User $user,
bool $dryRun = false
): IngestJob
{
if (!$this->lockService->acquire()) {
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();
}
}
}