add tagging

This commit is contained in:
team 1
2026-02-21 16:23:34 +01:00
parent 5a3852db12
commit cf5b473034
23 changed files with 1984 additions and 85 deletions

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity\TagRebuildJob;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
final class TagRebuildJobService
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly LoggerInterface $agentLogger,
private readonly string $projectDir,
) {}
public function enqueueAndStartAsync(): TagRebuildJob
{
$job = new TagRebuildJob();
$this->em->persist($job);
$this->em->flush();
$this->startAsync($job);
return $job;
}
private function startAsync(TagRebuildJob $job): void
{
$php = PHP_BINARY; // safest in runtime
$console = rtrim($this->projectDir, '/') . '/bin/console';
$cmd = sprintf(
'%s %s %s %s > /dev/null 2>&1 &',
escapeshellarg($php),
escapeshellarg($console),
'mto:agent:tags:job:run',
escapeshellarg((string)$job->getId())
);
$this->agentLogger->info('[tags] enqueue job async', [
'job' => (string)$job->getId(),
'cmd' => $cmd,
]);
@exec($cmd);
}
}