Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncG3WPaymentDatesForRegion
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 4
20
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 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 failed
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Jobs;
4
5use App\Services\FacturasService;
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-1293 — per-region G3W payment-date sync. Mirrors the shape of
17 * SyncG3WInvoicesForRegion (FIRE-1151): same 'g3w' rate-limit bucket,
18 * same per-region WithoutOverlapping key. Runs daily at 10:00 via the
19 * `invoices:sync-payment-dates` command.
20 */
21class SyncG3WPaymentDatesForRegion implements ShouldQueue
22{
23    use Dispatchable;
24    use InteractsWithQueue;
25    use Queueable;
26    use SerializesModels;
27
28    public int $tries = 3;
29
30    public array $backoff = [10, 30, 60];
31
32    public int $timeout = 600;
33
34    public function __construct(public readonly string $region) {}
35
36    public function middleware(): array
37    {
38        return [
39            (new WithoutOverlapping("g3w:payment-dates:{$this->region}"))
40                ->expireAfter(900)
41                ->dontRelease(),
42            new RateLimited('g3w'),
43        ];
44    }
45
46    public function handle(FacturasService $service): void
47    {
48        $start = microtime(true);
49        try {
50            $service->syncPaymentDatesForRegion($this->region);
51        } finally {
52            Log::channel('g3w_invoices')->info('SyncG3WPaymentDatesForRegion finished', [
53                'region' => $this->region,
54                'wall_ms' => (int) round((microtime(true) - $start) * 1000),
55                'attempt' => $this->attempts(),
56            ]);
57        }
58    }
59
60    public function failed(\Throwable $e): void
61    {
62        Log::channel('g3w_invoices')->error('SyncG3WPaymentDatesForRegion exhausted retries', [
63            'region' => $this->region,
64            'error' => $e->getMessage(),
65        ]);
66    }
67}