| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Jobs;
- use App\Models\User;
- use App\Notifications\Push\Prestador\Agendamento\NovaOportunidadePush;
- use App\Services\PushNotificationService;
- 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 SendOpportunityPushJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- public int $tries = 2;
- public int $timeout = 30;
- public array $backoff = [15, 60];
- public function __construct(
- public readonly int $userId,
- public readonly int $scheduleId,
- public readonly ?string $district = null,
- public readonly ?string $dateLabel = null,
- public readonly int $quantity = 1,
- ) {}
- public function handle(PushNotificationService $pushNotificationService): void
- {
- $user = User::find($this->userId);
- Log::info('----------entrou disparo-------------');
- if (! $user) {
- return;
- }
- Log::info('tem user');
- try {
- $pushNotificationService->sendToUser(
- $user,
- new NovaOportunidadePush($this->district, $this->dateLabel, $this->quantity)
- );
- } catch (\Throwable $exception) {
- Log::error('Falha ao enviar push de nova oportunidade', [
- 'user_id' => $this->userId,
- 'schedule_id' => $this->scheduleId,
- 'error' => $exception->getMessage(),
- ]);
- }
- }
- }
|