ExportReclamationsJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\SendWebSocketMessageEvent;
  4. use App\Services\ExportReclamationsService;
  5. use Exception;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Queue\Queueable;
  8. use Illuminate\Support\Facades\Log;
  9. class ExportReclamationsJob implements ShouldQueue
  10. {
  11. use Queueable;
  12. public function __construct(
  13. private readonly array $reclamationIds,
  14. private readonly int $userId,
  15. )
  16. {}
  17. public function handle(): void
  18. {
  19. try {
  20. $link = (new ExportReclamationsService())->handle($this->reclamationIds, $this->userId);
  21. Log::info('Export reclamations finished!');
  22. event(new SendWebSocketMessageEvent('Экспорт рекламаций готов!', $this->userId, ['success' => true, 'link' => $link]));
  23. } catch (Exception $e) {
  24. Log::error('Export reclamations failed! ' . $e->getMessage());
  25. event(new SendWebSocketMessageEvent('Ошибка экспорта рекламаций! ', $this->userId, ['error' => $e->getMessage()]));
  26. }
  27. }
  28. }