| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- declare(strict_types=1);
- namespace App\Jobs;
- use App\Events\SendWebSocketMessageEvent;
- use App\Services\ProductionOrderDocumentService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- use Throwable;
- class GenerateProductionOrderFileJob implements ShouldQueue
- {
- use Queueable;
- public int $timeout = 600;
- public int $tries = 2;
- /** @param list<int> $itemIds */
- public function __construct(
- private readonly string $type,
- private readonly int $orderId,
- private readonly int $userId,
- private readonly ?int $relatedId = null,
- private readonly array $itemIds = [],
- ) {}
- public function handle(ProductionOrderDocumentService $service): void
- {
- try {
- $file = $service->generate(
- $this->type,
- $this->orderId,
- $this->userId,
- $this->relatedId,
- $this->itemIds,
- );
- event(new SendWebSocketMessageEvent(
- 'Файл по заказу готов!',
- $this->userId,
- ['link' => $file->link],
- ));
- } catch (Throwable $exception) {
- Log::error('Production order file generation failed.', [
- 'type' => $this->type,
- 'order_id' => $this->orderId,
- 'user_id' => $this->userId,
- 'error' => $exception->getMessage(),
- ]);
- event(new SendWebSocketMessageEvent(
- 'Ошибка формирования файла: '.$exception->getMessage(),
- $this->userId,
- ['error' => $exception->getMessage()],
- ));
- throw $exception;
- }
- }
- }
|