harden code
This commit is contained in:
60
src/Command/IngestRunJobCommand.php
Normal file
60
src/Command/IngestRunJobCommand.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\IngestJob;
|
||||
use App\Service\IngestOrchestrator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'mto:agent:ingest:run')]
|
||||
final class IngestRunJobCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly IngestOrchestrator $orchestrator,
|
||||
private readonly EntityManagerInterface $em,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('jobId', InputArgument::REQUIRED, 'UUID of IngestJob');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$jobId = (string) $input->getArgument('jobId');
|
||||
|
||||
/** @var IngestJob|null $job */
|
||||
$job = $this->em->getRepository(IngestJob::class)->find($jobId);
|
||||
|
||||
if (!$job) {
|
||||
$output->writeln('<error>IngestJob not found.</error>');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Idempotenz: wenn der Job bereits beendet ist, einfach ok zurück.
|
||||
if (in_array($job->getStatus(), [IngestJob::STATUS_COMPLETED, IngestJob::STATUS_FAILED, IngestJob::STATUS_ABORTED], true)) {
|
||||
$output->writeln('<info>Job already finished.</info>');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
try {
|
||||
$output->writeln(sprintf('<info>Running ingest job %s ...</info>', (string) $job->getId()));
|
||||
$this->orchestrator->runExistingJob($job, false);
|
||||
$output->writeln('<info>Job completed.</info>');
|
||||
return Command::SUCCESS;
|
||||
} catch (\Throwable $e) {
|
||||
$output->writeln(sprintf('<error>Job failed: %s</error>', $e->getMessage()));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class KnowledgeIngestCommand extends Command
|
||||
|
||||
$output->writeln('Starting ingest...');
|
||||
|
||||
$job = $this->orchestrator->runForVersion($version, $user, false);
|
||||
$job = $this->orchestrator->runForVersion($version, $user);
|
||||
|
||||
$output->writeln(sprintf('<info>Ingest completed. Job: %s</info>', (string) $job->getId()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user