add tagging
This commit is contained in:
51
src/Service/TagRebuildJobService.php
Normal file
51
src/Service/TagRebuildJobService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user