feat(dump): run dump creation asynchronously via Messenger
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\MessageQueue\Handler;
|
||||
|
||||
use AeonDumpManager\MessageQueue\Message\CreateDumpMessage;
|
||||
use AeonDumpManager\Service\DumpJobStatusService;
|
||||
use AeonDumpManager\Service\DumpService;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler]
|
||||
class CreateDumpHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DumpService $dumpService,
|
||||
private readonly DumpJobStatusService $jobStatus,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(CreateDumpMessage $message): void
|
||||
{
|
||||
$jobId = $message->getJobId();
|
||||
$this->jobStatus->markRunning($jobId);
|
||||
|
||||
try {
|
||||
$this->dumpService->createAsync($jobId, $this->jobStatus);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->jobStatus->markFailed($jobId, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\MessageQueue\Message;
|
||||
|
||||
use Shopware\Core\Framework\MessageQueue\AsyncMessageInterface;
|
||||
|
||||
class CreateDumpMessage implements AsyncMessageInterface
|
||||
{
|
||||
public function __construct(private readonly string $jobId)
|
||||
{
|
||||
}
|
||||
|
||||
public function getJobId(): string
|
||||
{
|
||||
return $this->jobId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user