Skip to content

Commit

Permalink
Logger In ApiWriter (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
J0rdyV authored Jun 11, 2024
1 parent 74a52f2 commit fad0693
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Component/Akeneo/Client/ApiWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Misery\Component\Common\Pipeline\Exception\InvalidItemException;
use Misery\Component\Common\Processor\BatchSizeProcessor;
use Misery\Component\Writer\ItemWriterInterface;
use Psr\Log\LoggerInterface;

class ApiWriter implements ItemWriterInterface
{
Expand All @@ -19,16 +20,19 @@ class ApiWriter implements ItemWriterInterface
private $method;
/** @var BatchSizeProcessor */
private $batch;
/** @var LoggerInterface */
private $logger;

// TODO: add support for batching
private $pack = [];

public function __construct(ApiClientInterface $client, ApiEndpointInterface $endpoint, string $method = null)
public function __construct(ApiClientInterface $client, ApiEndpointInterface $endpoint, string $method = null, LoggerInterface $logger = null)
{
$this->client = $client;
$this->endpoint = $endpoint;
$this->method = $method;
$this->batch = new BatchSizeProcessor(10);
$this->logger = $logger;
}

public function write(array $data): void
Expand All @@ -46,7 +50,11 @@ public function write(array $data): void
if (count($this->pack) === 100) {
$item = $data;
$this->batch->next();
echo $this->batch->hasNewBatchPart() ? $this->batch->getBatchPart().'k':'.';
if($this->logger !== null) {
$this->logger->info('ApiWriter Progress : '.$this->batch->getBatchPart().'k');
} else {
echo $this->batch->hasNewBatchPart() ? $this->batch->getBatchPart().'k':'.';
}
$data = $this->pack;
$this->pack = [];
$this->pack[] = $item;
Expand Down
3 changes: 2 additions & 1 deletion src/Component/Akeneo/Client/HttpWriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public function createFromConfiguration(array $configuration, Configuration $con
return new ApiWriter(
$account,
new $endpoint,
$method
$method,
$config->getLogger()
);
}

Expand Down

0 comments on commit fad0693

Please sign in to comment.