Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DispatchDueVisitRemindersJob | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Visits\Infrastructure\Jobs; |
| 6 | |
| 7 | use Illuminate\Bus\Queueable; |
| 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
| 9 | use Illuminate\Foundation\Bus\Dispatchable; |
| 10 | use Illuminate\Queue\InteractsWithQueue; |
| 11 | use Illuminate\Queue\SerializesModels; |
| 12 | use ImovelZapAi\Visits\Domain\Enums\VisitReminderStatus; |
| 13 | use ImovelZapAi\Visits\Infrastructure\Persistence\Eloquent\VisitReminderModel; |
| 14 | |
| 15 | final class DispatchDueVisitRemindersJob implements ShouldQueue |
| 16 | { |
| 17 | use Dispatchable; |
| 18 | use InteractsWithQueue; |
| 19 | use Queueable; |
| 20 | use SerializesModels; |
| 21 | |
| 22 | public int $tries = 1; |
| 23 | |
| 24 | public function __construct() |
| 25 | { |
| 26 | $this->onQueue((string) config('visits.queue', 'visits')); |
| 27 | } |
| 28 | |
| 29 | public function handle(): void |
| 30 | { |
| 31 | VisitReminderModel::query() |
| 32 | ->where('status', VisitReminderStatus::Pending) |
| 33 | ->where('scheduled_for', '<=', now()) |
| 34 | ->orderBy('scheduled_for') |
| 35 | ->limit(100) |
| 36 | ->get() |
| 37 | ->each(function (VisitReminderModel $reminder): void { |
| 38 | SendVisitReminderJob::dispatch($reminder->id, $reminder->tenant_id) |
| 39 | ->onQueue((string) config('visits.queue', 'visits')); |
| 40 | }); |
| 41 | } |
| 42 | } |