| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- declare(strict_types=1);
- namespace App\Jobs\Export;
- use App\Events\SendWebSocketMessageEvent;
- use App\Services\Export\ExportTechnicalDescriptionsService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- use Throwable;
- class ExportTechnicalDescriptionsJob implements ShouldQueue
- {
- use Queueable;
- public int $timeout = 600;
- public int $tries = 2;
- /** @param list<int> $itemIds */
- public function __construct(
- private readonly array $itemIds,
- private readonly string $descriptionMode,
- private readonly bool $separateDocuments,
- private readonly int $userId,
- ) {}
- public function handle(ExportTechnicalDescriptionsService $service): void
- {
- try {
- $file = $service->handle(
- $this->itemIds,
- $this->descriptionMode,
- $this->separateDocuments,
- $this->userId,
- );
- event(new SendWebSocketMessageEvent(
- 'Экспорт технических описаний завершён!',
- $this->userId,
- ['link' => $file->link],
- ));
- } catch (Throwable $exception) {
- Log::error('Technical descriptions export failed.', [
- 'user_id' => $this->userId,
- 'item_ids' => $this->itemIds,
- 'error' => $exception->getMessage(),
- ]);
- event(new SendWebSocketMessageEvent(
- 'Ошибка экспорта технических описаний: '.$exception->getMessage(),
- $this->userId,
- ['error' => $exception->getMessage()],
- ));
- throw $exception;
- }
- }
- }
|