init
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Cron;
|
||||
|
||||
use Esun\LingxingErp\Model\Api\ApiException;
|
||||
use Esun\LingxingErp\Model\Config;
|
||||
use Esun\LingxingErp\Model\Shipment\ShipmentPuller;
|
||||
use Esun\LingxingErp\Model\Sync\LogWriter;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class PullShipments
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Config $config,
|
||||
private readonly ShipmentPuller $puller,
|
||||
private readonly LogWriter $logWriter,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
if (!$this->config->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
$started = microtime(true);
|
||||
try {
|
||||
$this->puller->pull();
|
||||
} catch (\Throwable $exception) {
|
||||
$response = $exception instanceof ApiException ? $exception->getResponse() : [];
|
||||
$this->logWriter->write([
|
||||
'direction' => 'pull', 'operation' => 'shipment_pull', 'entity_type' => 'shipment',
|
||||
'status' => 'failed', 'attempt_number' => 1,
|
||||
'error_code' => $exception instanceof ApiException ? $exception->getErrorCode() : (string)$exception->getCode(),
|
||||
'error_message' => $exception->getMessage(), 'request_id' => (string)($response['request_id'] ?? ''),
|
||||
'response_payload' => $response,
|
||||
'duration_ms' => (int)round((microtime(true) - $started) * 1000),
|
||||
]);
|
||||
$this->logger->error('Unable to pull Lingxing shipments.', ['exception' => $exception]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user