SuperSeller3000/src/Infrastructure/Messenger/Handler/PhotoUploadHandler.php

52 lines
1.5 KiB
PHP
Raw Normal View History

<?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->markProcessing();
$this->jobRepository->save($job);
$result = $this->visionAgent->analyze($message->storedPhotoPath);
if ('' === $result['model']) {
$job->markNeedsReview('OllamaVisionAgent: no model name detected on nameplate');
$this->jobRepository->save($job);
return;
}
$this->bus->dispatch(new SpecsResearchMessage(
jobId: $message->jobId,
articleTypeId: $message->articleTypeId,
modelName: $result['model'],
serialNumber: $result['serial'],
));
}
}