ExportMafJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\SendWebSocketMessageEvent;
  4. use App\Services\ExportMafService;
  5. use App\Services\ExportService;
  6. use Exception;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Queue\Queueable;
  9. use Illuminate\Support\Facades\Log;
  10. class ExportMafJob implements ShouldQueue
  11. {
  12. use Queueable;
  13. /**
  14. * Create a new job instance.
  15. */
  16. public function __construct(
  17. private readonly int $userId,
  18. private readonly array $filters
  19. )
  20. {}
  21. /**
  22. * Execute the job.
  23. */
  24. public function handle(): void
  25. {
  26. try {
  27. $file = (new ExportMafService())->handle($this->userId);
  28. Log::info('ExportMaf job done!');
  29. Log::info($file);
  30. event(new SendWebSocketMessageEvent('Экспорт завершён!', $this->userId, ['download' => $file]));
  31. } catch (Exception $e) {
  32. Log::info('ExportCatalog job failed!');
  33. event(new SendWebSocketMessageEvent('Ошибка экспорта! ' . $e->getMessage(), $this->userId, ['error' => $e->getMessage()]));
  34. }
  35. }
  36. }