Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CheckQuotationDuplicate
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
12
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
 handle
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Jobs;
4
5use Illuminate\Bus\Queueable;
6use Illuminate\Contracts\Queue\ShouldQueue;
7use Illuminate\Foundation\Bus\Dispatchable;
8use Illuminate\Queue\InteractsWithQueue;
9use Illuminate\Queue\SerializesModels;
10
11/**
12 * FIRE-1147: async wrapper for the Lambda duplicate-checker curl call that
13 * was previously inline in Quotations::create_quotation:204-219. The original
14 * code already discarded the response ($response and $httpCode were captured
15 * but never used downstream), so this migration is purely a latency win —
16 * the user's `create_quotation` HTTP response no longer waits 3-5 s for the
17 * Lambda roundtrip.
18 *
19 * No retries: same fire-and-forget semantics as before. On curl failure
20 * we log and move on (matches the pre-existing error_log behaviour).
21 */
22class CheckQuotationDuplicate implements ShouldQueue
23{
24    use Dispatchable;
25    use InteractsWithQueue;
26    use Queueable;
27    use SerializesModels;
28
29    public int $tries = 1;
30    public int $timeout = 30;
31
32    public function __construct(public readonly array $payload) {}
33
34    public function handle(): void
35    {
36        $ch = curl_init('https://2lsarnb35o6evhgwmfedrsxk3i0lqzzq.lambda-url.eu-west-2.on.aws/checkduplicate');
37        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
38        curl_setopt($ch, CURLOPT_POST, true);
39        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->payload));
40        curl_setopt($ch, CURLOPT_HTTPHEADER, [
41            'Content-Type: application/json',
42        ]);
43
44        curl_exec($ch);
45
46        if (curl_errno($ch)) {
47            error_log('CheckQuotationDuplicate cURL error: '.curl_error($ch));
48        }
49
50        curl_close($ch);
51    }
52}