SendUserNotificationChannelJob.php 962 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\NotificationService;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Foundation\Queue\Queueable;
  6. use Throwable;
  7. class SendUserNotificationChannelJob implements ShouldQueue
  8. {
  9. use Queueable;
  10. public int $tries = 3;
  11. public int $backoff = 60;
  12. public function __construct(
  13. private readonly int $userNotificationId,
  14. private readonly string $channel,
  15. ) {}
  16. public function handle(NotificationService $notificationService): void
  17. {
  18. $notificationService->deliverChannel(
  19. $this->userNotificationId,
  20. $this->channel,
  21. $this->attempts(),
  22. );
  23. }
  24. public function failed(?Throwable $exception): void
  25. {
  26. app(NotificationService::class)->markDeadLetter(
  27. $this->userNotificationId,
  28. $this->channel,
  29. $this->attempts(),
  30. $exception?->getMessage(),
  31. );
  32. }
  33. }