SuperSeller3000/src/Infrastructure/Messenger/Handler/PhotoUploadHandler.php
Simon Kuehn 321f6aaa05 fix: only block vision pipeline if nothing at all was readable
Previously blocked on needs_review when model name/number were empty,
even if manufacturer or serial were detected. Now proceeds to specs
research whenever any useful field was extracted, only blocking when the
nameplate was completely unreadable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 10:11:30 +00:00

66 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Infrastructure\Messenger\Handler;
use App\Domain\Pipeline\Repository\AIPipelineJobRepositoryInterface;
use App\Infrastructure\AI\Agent\OllamaVisionAgent;
use App\Infrastructure\Messenger\Message\PhotoUploadMessage;
use App\Infrastructure\Messenger\Message\SpecsResearchMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Uid\Uuid;
#[AsMessageHandler]
final class PhotoUploadHandler
{
public function __construct(
private readonly OllamaVisionAgent $visionAgent,
private readonly AIPipelineJobRepositoryInterface $jobRepository,
private readonly MessageBusInterface $bus,
) {
}
public function __invoke(PhotoUploadMessage $message): void
{
$job = $this->jobRepository->findById(Uuid::fromString($message->jobId));
if (null === $job) {
return;
}
$job->incrementAttempt();
$job->markProcessing();
$this->jobRepository->save($job);
$result = $this->visionAgent->analyze($message->storedPhotoPath);
$job->recordStep('vision', [
'manufacturer' => $result['manufacturer'],
'modelName' => $result['modelName'],
'modelNumber' => $result['modelNumber'],
'serial' => $result['serial'],
]);
$this->jobRepository->save($job);
$hasAnyInfo = '' !== $result['manufacturer']
|| '' !== $result['modelName']
|| '' !== $result['modelNumber'];
if (!$hasAnyInfo) {
$job->markNeedsReview('OllamaVisionAgent: nothing readable on nameplate');
$this->jobRepository->save($job);
return;
}
$this->bus->dispatch(new SpecsResearchMessage(
jobId: $message->jobId,
articleTypeId: $message->articleTypeId,
modelNumber: $result['modelNumber'],
modelName: $result['modelName'],
serialNumber: $result['serial'],
manufacturer: $result['manufacturer'],
));
}
}