ExportMafRegistryJob.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\SendWebSocketMessageEvent;
  4. use App\Services\ExportMafRegistryService;
  5. use Exception;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Queue\Queueable;
  8. use Illuminate\Support\Facades\Log;
  9. class ExportMafRegistryJob implements ShouldQueue
  10. {
  11. use Queueable;
  12. public function __construct(
  13. private readonly int $userId,
  14. private readonly string $updNumber,
  15. private readonly int $year,
  16. ) {
  17. }
  18. public function handle(): void
  19. {
  20. try {
  21. $link = (new ExportMafRegistryService())->handle($this->userId, $this->updNumber, $this->year);
  22. Log::info('ExportMafRegistry job done!');
  23. event(new SendWebSocketMessageEvent('Реестр на оплату сформирован!', $this->userId, ['success' => true, 'link' => $link]));
  24. } catch (Exception $e) {
  25. Log::error('ExportMafRegistry job failed! ' . $e->getMessage());
  26. event(new SendWebSocketMessageEvent('Ошибка формирования реестра на оплату! ', $this->userId, ['error' => $e->getMessage()]));
  27. }
  28. }
  29. }