remove redundant lock service
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Entity\Document;
|
|||||||
use App\Entity\DocumentVersion;
|
use App\Entity\DocumentVersion;
|
||||||
use App\Index\IndexMetaManager;
|
use App\Index\IndexMetaManager;
|
||||||
use App\Knowledge\Ingest\KnowledgeIngestService;
|
use App\Knowledge\Ingest\KnowledgeIngestService;
|
||||||
|
use App\Service\LockService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Uid\Uuid;
|
use Symfony\Component\Uid\Uuid;
|
||||||
@@ -23,10 +24,12 @@ final readonly class IngestFlow
|
|||||||
private ChunkWriteService $chunkWriteService,
|
private ChunkWriteService $chunkWriteService,
|
||||||
private VectorRebuildService $vectorRebuildService,
|
private VectorRebuildService $vectorRebuildService,
|
||||||
private IndexMetaManager $metaManager,
|
private IndexMetaManager $metaManager,
|
||||||
private IngestLockService $lockService,
|
private LockService $lockService,
|
||||||
private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
private EntityManagerInterface $em,
|
private EntityManagerInterface $em,
|
||||||
) {}
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// =========================================================
|
// =========================================================
|
||||||
// DOCUMENT INGEST
|
// DOCUMENT INGEST
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Ingest;
|
|
||||||
|
|
||||||
final class IngestLockService
|
|
||||||
{
|
|
||||||
private string $lockFilePath;
|
|
||||||
|
|
||||||
/** @var resource|null */
|
|
||||||
private $handle = null;
|
|
||||||
|
|
||||||
public function __construct(string $projectDir)
|
|
||||||
{
|
|
||||||
$this->lockFilePath = rtrim($projectDir, '/') . '/var/knowledge/locks/ingest.lock';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function acquire(): void
|
|
||||||
{
|
|
||||||
$dir = dirname($this->lockFilePath);
|
|
||||||
|
|
||||||
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
|
|
||||||
throw new \RuntimeException('Unable to create lock directory.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->handle = fopen($this->lockFilePath, 'c');
|
|
||||||
|
|
||||||
if ($this->handle === false) {
|
|
||||||
throw new \RuntimeException('Unable to open ingest lock file.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!flock($this->handle, LOCK_EX | LOCK_NB)) {
|
|
||||||
throw new \RuntimeException('Another ingest process is already running.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function release(): void
|
|
||||||
{
|
|
||||||
if ($this->handle !== null) {
|
|
||||||
flock($this->handle, LOCK_UN);
|
|
||||||
fclose($this->handle);
|
|
||||||
$this->handle = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
$this->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user