ExportScheduleJob.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\SendWebSocketMessageEvent;
  4. use App\Services\ExportScheduleService;
  5. use Exception;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Queue\Queueable;
  8. use Illuminate\Support\Collection;
  9. use Illuminate\Support\Facades\Log;
  10. class ExportScheduleJob implements ShouldQueue
  11. {
  12. use Queueable;
  13. /**
  14. * Create a new job instance.
  15. */
  16. public function __construct(
  17. private readonly Collection $schedules,
  18. private readonly int $userId,
  19. )
  20. {}
  21. /**
  22. * Execute the job.
  23. */
  24. public function handle(): void
  25. {
  26. try {
  27. $link = (new ExportScheduleService())->handle($this->schedules, $this->userId);
  28. Log::info('Export schedule finished!');
  29. event(new SendWebSocketMessageEvent('Экспорт графика готов!', $this->userId, ['success' => true, 'link' => $link]));
  30. } catch (Exception $e) {
  31. Log::error('Export schedule failed! ' . $e->getMessage());
  32. event(new SendWebSocketMessageEvent('Ошибка экспорта графика! ', $this->userId, ['error' => $e->getMessage()]));
  33. }
  34. }
  35. }