ExportCatalog.php 1.1 KB

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