ScheduleStartingSoonJob.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Schedule;
  4. use App\Services\ScheduleService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Illuminate\Support\Facades\Log;
  11. class ScheduleStartingSoonJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. public function __construct(
  15. public int $scheduleId
  16. ) {}
  17. public function handle(): void
  18. {
  19. try {
  20. $schedule = Schedule::with([
  21. 'client.user',
  22. 'provider.user',
  23. ])->find($this->scheduleId);
  24. if (! $schedule) {
  25. return;
  26. }
  27. // Só envia a notificação se o agendamento ainda estiver pago.
  28. if ($schedule->status !== 'paid') {
  29. return;
  30. }
  31. app(ScheduleService::class)
  32. ->sendScheduleStartingSoonPushes($schedule);
  33. } catch (\Throwable $e) {
  34. Log::error(
  35. 'Erro ao enviar push de agendamento próximo.',
  36. [
  37. 'schedule_id' => $this->scheduleId,
  38. 'error' => $e->getMessage(),
  39. ]
  40. );
  41. }
  42. }
  43. }