feat: Implement Allegro Order Sync and Status Management
- Added AllegroOrderSyncStateRepository for managing sync state with Allegro orders. - Introduced AllegroOrdersSyncService to handle the synchronization of orders from Allegro. - Created AllegroStatusDiscoveryService to discover and store order statuses from Allegro. - Developed AllegroStatusMappingRepository for managing status mappings between Allegro and OrderPro. - Implemented AllegroStatusSyncService to facilitate status synchronization. - Added CronSettingsController for managing cron job settings related to Allegro integration.
This commit is contained in:
@@ -13,7 +13,21 @@ use App\Core\Support\Logger;
|
||||
use App\Core\Support\Session;
|
||||
use App\Core\View\Template;
|
||||
use App\Modules\Auth\AuthService;
|
||||
use App\Modules\Cron\AllegroOrdersImportHandler;
|
||||
use App\Modules\Cron\AllegroStatusSyncHandler;
|
||||
use App\Modules\Cron\AllegroTokenRefreshHandler;
|
||||
use App\Modules\Cron\CronRepository;
|
||||
use App\Modules\Cron\CronRunner;
|
||||
use App\Modules\Orders\OrderImportRepository;
|
||||
use App\Modules\Orders\OrdersRepository;
|
||||
use App\Modules\Settings\AllegroApiClient;
|
||||
use App\Modules\Settings\AllegroIntegrationRepository;
|
||||
use App\Modules\Settings\AllegroOrderImportService;
|
||||
use App\Modules\Settings\AllegroOrdersSyncService;
|
||||
use App\Modules\Settings\AllegroOrderSyncStateRepository;
|
||||
use App\Modules\Settings\AllegroOAuthClient;
|
||||
use App\Modules\Settings\AllegroStatusSyncService;
|
||||
use App\Modules\Settings\AllegroStatusMappingRepository;
|
||||
use App\Modules\Settings\OrderStatusRepository;
|
||||
use App\Modules\Users\UserRepository;
|
||||
use Throwable;
|
||||
@@ -70,6 +84,7 @@ final class Application
|
||||
public function run(): void
|
||||
{
|
||||
$request = Request::capture();
|
||||
$this->maybeRunCronOnWeb($request);
|
||||
$response = $this->router->dispatch($request);
|
||||
$response->send();
|
||||
}
|
||||
@@ -215,7 +230,87 @@ final class Application
|
||||
|
||||
private function maybeRunCronOnWeb(Request $request): void
|
||||
{
|
||||
return;
|
||||
$path = $request->path();
|
||||
if ($path === '/health' || str_starts_with($path, '/assets/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$repository = new CronRepository($this->db);
|
||||
$runOnWeb = $repository->getBoolSetting(
|
||||
'cron_run_on_web',
|
||||
(bool) $this->config('app.cron.run_on_web_default', false)
|
||||
);
|
||||
if (!$runOnWeb) {
|
||||
return;
|
||||
}
|
||||
|
||||
$webLimit = $repository->getIntSetting(
|
||||
'cron_web_limit',
|
||||
(int) $this->config('app.cron.web_limit_default', 5),
|
||||
1,
|
||||
100
|
||||
);
|
||||
|
||||
if ($this->isWebCronThrottled(10)) {
|
||||
return;
|
||||
}
|
||||
if (!$this->acquireWebCronLock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$integrationRepository = new AllegroIntegrationRepository(
|
||||
$this->db,
|
||||
(string) $this->config('app.integrations.secret', '')
|
||||
);
|
||||
$oauthClient = new AllegroOAuthClient();
|
||||
$apiClient = new AllegroApiClient();
|
||||
$statusMappingRepository = new AllegroStatusMappingRepository($this->db);
|
||||
$orderImportService = new AllegroOrderImportService(
|
||||
$integrationRepository,
|
||||
$oauthClient,
|
||||
$apiClient,
|
||||
new OrderImportRepository($this->db),
|
||||
$statusMappingRepository
|
||||
);
|
||||
$ordersSyncService = new AllegroOrdersSyncService(
|
||||
$integrationRepository,
|
||||
new AllegroOrderSyncStateRepository($this->db),
|
||||
$oauthClient,
|
||||
$apiClient,
|
||||
$orderImportService
|
||||
);
|
||||
|
||||
$runner = new CronRunner(
|
||||
$repository,
|
||||
$this->logger,
|
||||
[
|
||||
'allegro_token_refresh' => new AllegroTokenRefreshHandler(
|
||||
$integrationRepository,
|
||||
$oauthClient
|
||||
),
|
||||
'allegro_orders_import' => new AllegroOrdersImportHandler(
|
||||
$ordersSyncService
|
||||
),
|
||||
'allegro_status_sync' => new AllegroStatusSyncHandler(
|
||||
new AllegroStatusSyncService(
|
||||
$repository,
|
||||
$ordersSyncService
|
||||
)
|
||||
),
|
||||
]
|
||||
);
|
||||
$runner->run($webLimit);
|
||||
} finally {
|
||||
$this->releaseWebCronLock();
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
$this->logger->error('Web cron run failed', [
|
||||
'message' => $exception->getMessage(),
|
||||
'path' => $path,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function isWebCronThrottled(int $minIntervalSeconds): bool
|
||||
|
||||
Reference in New Issue
Block a user