Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncCofraiClientsForRegion
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 middleware
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
6
 failed
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Jobs;
4
5use App\Services\CofraiClientSyncService;
6use Illuminate\Bus\Queueable;
7use Illuminate\Contracts\Queue\ShouldQueue;
8use Illuminate\Foundation\Bus\Dispatchable;
9use Illuminate\Queue\InteractsWithQueue;
10use Illuminate\Queue\Middleware\RateLimited;
11use Illuminate\Queue\Middleware\WithoutOverlapping;
12use Illuminate\Queue\SerializesModels;
13use Illuminate\Support\Facades\Log;
14
15/**
16 * FIRE-1077: Cofrai parallel to SyncG3WClientsForRegion.
17 */
18class SyncCofraiClientsForRegion implements ShouldQueue
19{
20    use Dispatchable;
21    use InteractsWithQueue;
22    use Queueable;
23    use SerializesModels;
24
25    public int $tries = 3;
26
27    public array $backoff = [10, 30, 60];
28
29    public int $timeout = 600;
30
31    public function __construct(
32        public readonly string $date,
33        public readonly string $region,
34    ) {}
35
36    public function middleware(): array
37    {
38        return [
39            (new WithoutOverlapping("cofrai:clients:{$this->region}"))
40                ->expireAfter(900)
41                ->dontRelease(),
42            new RateLimited('cofrai'),
43        ];
44    }
45
46    public function handle(CofraiClientSyncService $service): void
47    {
48        $start = microtime(true);
49        try {
50            $stats = $service->syncRegion($this->date, $this->region);
51            Log::channel('cofrai')->info('SyncCofraiClientsForRegion finished', [
52                'region' => $this->region,
53                'date' => $this->date,
54                'wall_ms' => (int) round((microtime(true) - $start) * 1000),
55                'stats' => $stats,
56                'attempt' => $this->attempts(),
57            ]);
58        } catch (\Throwable $e) {
59            Log::channel('cofrai')->error('SyncCofraiClientsForRegion failed', [
60                'region' => $this->region,
61                'date' => $this->date,
62                'wall_ms' => (int) round((microtime(true) - $start) * 1000),
63                'error' => $e->getMessage(),
64            ]);
65            throw $e;
66        }
67    }
68
69    public function failed(\Throwable $e): void
70    {
71        Log::channel('cofrai')->error('SyncCofraiClientsForRegion exhausted retries', [
72            'region' => $this->region,
73            'date' => $this->date,
74            'error' => $e->getMessage(),
75        ]);
76    }
77}