| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Jobs\Export;
- use App\Events\SendWebSocketMessageEvent;
- use App\Services\Export\ExportYearDataService;
- use Exception;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- class ExportYearDataJob implements ShouldQueue
- {
- use Queueable;
- /**
- * Количество попыток выполнения задания.
- */
- public int $tries = 1;
- /**
- * Таймаут выполнения задания (30 минут).
- */
- public int $timeout = 1800;
- public function __construct(
- private readonly int $year,
- private readonly int $userId,
- ) {}
- public function handle(): void
- {
- try {
- Log::info("ExportYearDataJob started for year {$this->year}");
- $service = new ExportYearDataService($this->year, $this->userId);
- $downloadLink = $service->handle();
- $stats = $service->getStats();
- Log::info("ExportYearDataJob completed for year {$this->year}", $stats);
- event(new SendWebSocketMessageEvent(
- "Экспорт данных за {$this->year} год завершён!",
- $this->userId,
- [
- 'success' => true,
- 'download' => $downloadLink,
- 'year' => $this->year,
- 'stats' => $stats,
- ]
- ));
- } catch (Exception $e) {
- Log::error("ExportYearDataJob failed for year {$this->year}: " . $e->getMessage(), [
- 'trace' => $e->getTraceAsString()
- ]);
- event(new SendWebSocketMessageEvent(
- "Ошибка экспорта данных за {$this->year} год: " . $e->getMessage(),
- $this->userId,
- [
- 'error' => $e->getMessage(),
- 'year' => $this->year,
- ]
- ));
- }
- }
- }
|