Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
8.33% covered (danger)
8.33%
1 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CheckQuotationDuplicate
8.33% covered (danger)
8.33%
1 / 12
50.00% covered (danger)
50.00%
1 / 2
9.93
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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
31    public int $timeout = 30;
32
33    public function __construct(public readonly array $payload) {}
34
35    public function handle(): void
36    {
37        $ch = curl_init('https://2lsarnb35o6evhgwmfedrsxk3i0lqzzq.lambda-url.eu-west-2.on.aws/checkduplicate');
38        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
39        curl_setopt($ch, CURLOPT_POST, true);
40        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->payload));
41        curl_setopt($ch, CURLOPT_HTTPHEADER, [
42            'Content-Type: application/json',
43        ]);
44
45        curl_exec($ch);
46
47        if (curl_errno($ch)) {
48            error_log('CheckQuotationDuplicate cURL error: '.curl_error($ch));
49        }
50
51        curl_close($ch);
52    }
53}