Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SendVisitReminderJob
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Visits\Infrastructure\Jobs;
6
7use Illuminate\Bus\Queueable;
8use Illuminate\Contracts\Queue\ShouldQueue;
9use Illuminate\Foundation\Bus\Dispatchable;
10use Illuminate\Queue\InteractsWithQueue;
11use Illuminate\Queue\SerializesModels;
12use ImovelZapAi\Tenancy\Support\TenantContext;
13use ImovelZapAi\Visits\Application\Actions\SendVisitReminderAction;
14
15final class SendVisitReminderJob implements ShouldQueue
16{
17    use Dispatchable;
18    use InteractsWithQueue;
19    use Queueable;
20    use SerializesModels;
21
22    public int $tries = 3;
23
24    /** @var list<int> */
25    public array $backoff = [30, 60, 120];
26
27    public int $timeout = 60;
28
29    public function __construct(
30        public readonly string $reminderId,
31        public readonly string $tenantId,
32    ) {
33        $this->onQueue((string) config('visits.queue', 'visits'));
34    }
35
36    public function handle(SendVisitReminderAction $action): void
37    {
38        TenantContext::clear();
39        TenantContext::set($this->tenantId);
40
41        try {
42            $action->execute($this->reminderId, $this->tenantId);
43        } finally {
44            TenantContext::clear();
45        }
46    }
47}