harden semantic match sby tags
This commit is contained in:
@@ -12,11 +12,12 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
#[AsCommand(
|
#[AsCommand(
|
||||||
name: 'mto:agent:tags:job:run',
|
name: 'mto:agent:tags:job:run',
|
||||||
description: 'Run a single tag rebuild job (export tags.ndjson + build vector_tags.index) with lock'
|
description: 'Run a tag rebuild job (export tags.ndjson + build vector_tags.index) with lock'
|
||||||
)]
|
)]
|
||||||
final class TagRebuildRunJobCommand extends Command
|
final class TagRebuildRunJobCommand extends Command
|
||||||
{
|
{
|
||||||
@@ -31,13 +32,33 @@ final class TagRebuildRunJobCommand extends Command
|
|||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->addArgument('jobId', InputArgument::REQUIRED, 'TagRebuildJob UUID');
|
$this
|
||||||
|
->addArgument('jobId', InputArgument::OPTIONAL, 'Existing TagRebuildJob UUID')
|
||||||
|
->addOption('create', null, InputOption::VALUE_NONE, 'Create and immediately run a new TagRebuildJob');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$jobId = (string) $input->getArgument('jobId');
|
$jobId = $input->getArgument('jobId');
|
||||||
|
$create = (bool) $input->getOption('create');
|
||||||
|
|
||||||
|
if (!$create && !$jobId) {
|
||||||
|
$output->writeln('<error>You must provide either a jobId or use --create.</error>');
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($create && $jobId) {
|
||||||
|
$output->writeln('<error>Use either jobId OR --create, not both.</error>');
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($create) {
|
||||||
|
$job = new TagRebuildJob();
|
||||||
|
$this->em->persist($job);
|
||||||
|
$this->em->flush();
|
||||||
|
$jobId = $job->getId();
|
||||||
|
$output->writeln('<info>Created new TagRebuildJob: ' . $jobId . '</info>');
|
||||||
|
} else {
|
||||||
/** @var TagRebuildJob|null $job */
|
/** @var TagRebuildJob|null $job */
|
||||||
$job = $this->em->getRepository(TagRebuildJob::class)->find($jobId);
|
$job = $this->em->getRepository(TagRebuildJob::class)->find($jobId);
|
||||||
|
|
||||||
@@ -45,6 +66,7 @@ final class TagRebuildRunJobCommand extends Command
|
|||||||
$output->writeln('<error>Job not found.</error>');
|
$output->writeln('<error>Job not found.</error>');
|
||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$fh = null;
|
$fh = null;
|
||||||
|
|
||||||
@@ -53,6 +75,7 @@ final class TagRebuildRunJobCommand extends Command
|
|||||||
// LOCK INITIALIZATION
|
// LOCK INITIALIZATION
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
$lockDir = \dirname($this->lockFilePath);
|
$lockDir = \dirname($this->lockFilePath);
|
||||||
|
|
||||||
if (!\is_dir($lockDir) && !@\mkdir($lockDir, 0775, true) && !\is_dir($lockDir)) {
|
if (!\is_dir($lockDir) && !@\mkdir($lockDir, 0775, true) && !\is_dir($lockDir)) {
|
||||||
throw new \RuntimeException('Cannot create lock directory.');
|
throw new \RuntimeException('Cannot create lock directory.');
|
||||||
}
|
}
|
||||||
@@ -107,8 +130,10 @@ final class TagRebuildRunJobCommand extends Command
|
|||||||
}
|
}
|
||||||
catch (\Throwable $e) {
|
catch (\Throwable $e) {
|
||||||
|
|
||||||
|
if (isset($job)) {
|
||||||
$job->markFailed($e->getMessage());
|
$job->markFailed($e->getMessage());
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
$output->writeln('<error>FAILED: ' . $e->getMessage() . '</error>');
|
$output->writeln('<error>FAILED: ' . $e->getMessage() . '</error>');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user