| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Jobs;
- use App\Events\SendWebSocketMessageEvent;
- use App\Services\ExportMafRegistryService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- use Throwable;
- class ExportMafRegistryJob implements ShouldQueue
- {
- use Queueable;
- public function __construct(
- private readonly int $userId,
- private readonly string $updNumber,
- private readonly int $year,
- ) {
- }
- public function handle(): void
- {
- try {
- $link = (new ExportMafRegistryService())->handle($this->userId, $this->updNumber, $this->year);
- Log::info('ExportMafRegistry job done!');
- event(new SendWebSocketMessageEvent('Реестр на оплату сформирован!', $this->userId, ['success' => true, 'link' => $link]));
- } catch (Throwable $e) {
- $this->notifyFailure($e);
- }
- }
- public function failed(Throwable $e): void
- {
- $this->notifyFailure($e);
- }
- private function notifyFailure(Throwable $e): void
- {
- Log::error('ExportMafRegistry job failed.', [
- 'user_id' => $this->userId,
- 'upd_number' => $this->updNumber,
- 'year' => $this->year,
- 'exception' => $e,
- ]);
- event(new SendWebSocketMessageEvent(
- 'Ошибка формирования реестра на оплату! ' . $e->getMessage(),
- $this->userId,
- ['error' => $e->getMessage()]
- ));
- }
- }
|