-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c87a80d
commit 55af868
Showing
109 changed files
with
1,625 additions
and
1,132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Exceptions; | ||
|
||
class NotImplementedException extends \LogicException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Factory\Message\Batch; | ||
|
||
use Synolia\SyliusAkeneoPlugin\Message\Batch\BatchMessageInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
class BatchMessageFactory implements BatchMessageFactoryInterface | ||
{ | ||
public static function createFromPayload(PipelinePayloadInterface $payload, array $items): BatchMessageInterface | ||
{ | ||
return $payload->createBatchMessage($items); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Factory/Message/Batch/BatchMessageFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Factory\Message\Batch; | ||
|
||
use Synolia\SyliusAkeneoPlugin\Message\Batch\BatchMessageInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
interface BatchMessageFactoryInterface | ||
{ | ||
public static function createFromPayload(PipelinePayloadInterface $payload, array $items): BatchMessageInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Handler\Task; | ||
|
||
use Akeneo\Pim\ApiClient\Pagination\Page; | ||
use Akeneo\Pim\ApiClient\Pagination\PageInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Synolia\SyliusAkeneoPlugin\Factory\Message\Batch\BatchMessageFactoryInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
class SymfonyMessengerTaskHandler implements TaskHandlerInterface | ||
{ | ||
public const HANDLER_CODE = 'messenger'; | ||
|
||
public function __construct( | ||
protected EntityManagerInterface $entityManager, | ||
protected LoggerInterface $logger, | ||
private MessageBusInterface $bus, | ||
private BatchMessageFactoryInterface $batchMessageFactory, | ||
) { | ||
} | ||
|
||
public function support(PipelinePayloadInterface $pipelinePayload): bool | ||
{ | ||
return $pipelinePayload->getCommandContext()->getHandler() === self::HANDLER_CODE; | ||
} | ||
|
||
public function batch(PipelinePayloadInterface $pipelinePayload, array $items): void | ||
{ | ||
$this->bus->dispatch($this->batchMessageFactory->createFromPayload($pipelinePayload, $items)); | ||
} | ||
|
||
public function process(PipelinePayloadInterface $pipelinePayload): void | ||
{ | ||
} | ||
|
||
public function handle( | ||
PipelinePayloadInterface $pipelinePayload, | ||
ResourceCursorInterface|PageInterface $handleType, | ||
): void { | ||
$count = 0; | ||
$items = []; | ||
|
||
if ($handleType instanceof PageInterface) { | ||
$this->handleByPage($pipelinePayload, $handleType, $count, $items); | ||
} else { | ||
$this->handleByCursor($pipelinePayload, $handleType, $count, $items); | ||
} | ||
} | ||
|
||
private function handleByPage( | ||
PipelinePayloadInterface $payload, | ||
PageInterface $page, | ||
int &$count = 0, | ||
array &$items = [], | ||
): void { | ||
while ( | ||
($page instanceof Page && $page->hasNextPage()) || | ||
($page instanceof Page && !$page->hasPreviousPage()) || | ||
$page instanceof Page | ||
) { | ||
foreach ($page->getItems() as $item) { | ||
++$count; | ||
$items[] = $item; | ||
$identifiers[] = $item['code'] ?? $item['identifier']; | ||
|
||
if (0 === $count % $payload->getBatchSize()) { | ||
$this->logger->notice('Batching', ['codes' => $identifiers]); | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
$page = $page->getNextPage(); | ||
} | ||
|
||
if ($items !== []) { | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
private function handleByCursor( | ||
PipelinePayloadInterface $payload, | ||
ResourceCursorInterface $resourceCursor, | ||
int &$count = 0, | ||
array &$items = [], | ||
): void { | ||
foreach ($resourceCursor as $item) { | ||
++$count; | ||
$items[] = $item; | ||
$identifiers[] = $item['code']; | ||
Check failure on line 97 in src/Handler/Task/SymfonyMessengerTaskHandler.php GitHub Actions / PHP 8.2 Symfony 6.2.*
Check failure on line 97 in src/Handler/Task/SymfonyMessengerTaskHandler.php GitHub Actions / PHP 8.2 Symfony 6.2.*
Check failure on line 97 in src/Handler/Task/SymfonyMessengerTaskHandler.php GitHub Actions / PHP 8.2 Symfony 5.4.*
|
||
|
||
if (0 === $count % $payload->getBatchSize()) { | ||
$this->logger->notice('Batching', ['codes' => $identifiers]); | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
if ($items !== []) { | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
public function setUp(PipelinePayloadInterface $pipelinePayload): PipelinePayloadInterface | ||
{ | ||
return $pipelinePayload; | ||
} | ||
|
||
public function tearDown(PipelinePayloadInterface $pipelinePayload): PipelinePayloadInterface | ||
{ | ||
return $pipelinePayload; | ||
} | ||
} |
Oops, something went wrong.