remove redundant lock service
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Entity\Document;
|
||||
use App\Entity\DocumentVersion;
|
||||
use App\Index\IndexMetaManager;
|
||||
use App\Knowledge\Ingest\KnowledgeIngestService;
|
||||
use App\Service\LockService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
@@ -23,10 +24,12 @@ final readonly class IngestFlow
|
||||
private ChunkWriteService $chunkWriteService,
|
||||
private VectorRebuildService $vectorRebuildService,
|
||||
private IndexMetaManager $metaManager,
|
||||
private IngestLockService $lockService,
|
||||
private LockService $lockService,
|
||||
private LoggerInterface $logger,
|
||||
private EntityManagerInterface $em,
|
||||
) {}
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// DOCUMENT INGEST
|
||||
@@ -84,9 +87,9 @@ final readonly class IngestFlow
|
||||
$this->logger->warning('Chunk count approaching limit.', [
|
||||
'existing' => $existing,
|
||||
'incoming' => $incoming,
|
||||
'total' => $total,
|
||||
'total' => $total,
|
||||
'document' => (string)$documentId,
|
||||
'version' => (string)$version->getId(),
|
||||
'version' => (string)$version->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -178,7 +181,7 @@ final readonly class IngestFlow
|
||||
if ($warned) {
|
||||
$this->logger->warning('Chunk count approaching limit after global reindex.', [
|
||||
'incoming' => $incoming,
|
||||
'total' => $incoming,
|
||||
'total' => $incoming,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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