| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Jobs;
- use App\Models\Schedule;
- use App\Services\ScheduleService;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\Log;
- class ScheduleStartingSoonJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- public function __construct(
- public int $scheduleId
- ) {}
- public function handle(): void
- {
- try {
- $schedule = Schedule::with([
- 'client.user',
- 'provider.user',
- ])->find($this->scheduleId);
- if (! $schedule) {
- return;
- }
- // Só envia a notificação se o agendamento ainda estiver pago.
- if ($schedule->status !== 'paid') {
- return;
- }
- app(ScheduleService::class)
- ->sendScheduleStartingSoonPushes($schedule);
- } catch (\Throwable $e) {
- Log::error(
- 'Erro ao enviar push de agendamento próximo.',
- [
- 'schedule_id' => $this->scheduleId,
- 'error' => $e->getMessage(),
- ]
- );
- }
- }
- }
|