| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare(strict_types=1);
- namespace App\Jobs\Export;
- use App\Events\SendWebSocketMessageEvent;
- use App\Services\Export\ExportProductionOrdersService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- use Throwable;
- class ExportProductionOrdersJob implements ShouldQueue
- {
- use Queueable;
- public int $timeout = 600;
- public int $tries = 2;
- /** @param list<int> $orderIds */
- public function __construct(
- public readonly array $orderIds,
- public readonly int $userId,
- ) {}
- public function handle(ExportProductionOrdersService $service): void
- {
- try {
- $file = $service->handle($this->orderIds, $this->userId);
- event(new SendWebSocketMessageEvent(
- 'Экспорт графика заказов завершён!',
- $this->userId,
- ['link' => $file->link],
- ));
- } catch (Throwable $exception) {
- Log::error('Production orders export failed.', [
- 'user_id' => $this->userId,
- 'orders_count' => count($this->orderIds),
- 'error' => $exception->getMessage(),
- ]);
- event(new SendWebSocketMessageEvent(
- 'Ошибка экспорта графика заказов: '.$exception->getMessage(),
- $this->userId,
- ['error' => $exception->getMessage()],
- ));
- throw $exception;
- }
- }
- }
|