optimize code
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -12,18 +12,20 @@ use Symfony\Component\Uid\Uuid;
|
|||||||
final class IngestOrchestrator
|
final class IngestOrchestrator
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly LockService $lockService,
|
private readonly LockService $lockService,
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user