fix: reduce spooler timeout to prevent batch processing hang
- Reduce cURL timeout from 10s to 3s total (2s connection) - Add better error messages for spooler failures - Continue processing remaining items if one fails - Prevents getting stuck when spooler is slow/unreachable
This commit is contained in:
parent
25c1eaaa3d
commit
3ab2258b1b
@ -51,7 +51,7 @@ class SuperuserController extends BaseController
|
||||
$results = [];
|
||||
$db = \Config\Database::connect();
|
||||
|
||||
foreach ($accessNumbers as $accessnumber) {
|
||||
foreach ($accessNumbers as $index => $accessnumber) {
|
||||
$accessnumber = trim($accessnumber);
|
||||
if (empty($accessnumber)) {
|
||||
continue;
|
||||
@ -73,7 +73,7 @@ class SuperuserController extends BaseController
|
||||
continue;
|
||||
}
|
||||
|
||||
// Call report/{accessnumber}/pdf endpoint internally
|
||||
// Call PDF generation service
|
||||
$response = $this->callReportPdfEndpoint($accessnumber);
|
||||
|
||||
if ($response['success']) {
|
||||
|
||||
@ -105,17 +105,27 @@ class PdfBatchService
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($curlError) {
|
||||
throw new \Exception('Spooler connection failed: ' . $curlError);
|
||||
}
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
throw new \Exception('Failed to queue PDF generation');
|
||||
throw new \Exception('Spooler returned HTTP ' . $httpCode);
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (!isset($data['jobId'])) {
|
||||
throw new \Exception('Invalid spooler response');
|
||||
}
|
||||
|
||||
return $data['jobId'];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user