optimize code
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user