Update: 2026-05-08 14:44:54
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
use App\Core\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
use App\Core\Security;
|
||||
use App\Services\InvoiceProcessor;
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
$tenantId = $decoded['tenant_id'];
|
||||
@@ -57,11 +58,23 @@ $stmt = $db->prepare("
|
||||
");
|
||||
$stmt->execute([$batchId]);
|
||||
|
||||
// 3. If it's a single invoice, try triggering the worker in the background immediately
|
||||
// This helps if the Cron Job is delayed or failing.
|
||||
$workerPath = ROOT_PATH . '/app/cron/process_batches.php';
|
||||
$logPath = STORAGE_PATH . '/logs/cron.log';
|
||||
exec("php " . escapeshellarg($workerPath) . " >> " . escapeshellarg($logPath) . " 2>&1 &");
|
||||
// 3. If it's a single invoice, try processing it SYNCHRONOUSLY right now!
|
||||
if ($batch['total_images'] == 1) {
|
||||
// We need the queue ID for this batch
|
||||
$queueStmt = $db->prepare("SELECT id FROM invoice_processing_queue WHERE batch_id = ? AND status = 'pending' LIMIT 1");
|
||||
$queueStmt->execute([$batchId]);
|
||||
$queueId = $queueStmt->fetchColumn();
|
||||
|
||||
if ($queueId) {
|
||||
InvoiceProcessor::processQueueItem((int)$queueId);
|
||||
}
|
||||
} else {
|
||||
// For multiple invoices, try triggering the worker in the background
|
||||
$workerPath = ROOT_PATH . '/app/cron/process_batches.php';
|
||||
$logPath = STORAGE_PATH . '/logs/cron.log';
|
||||
// Mute exec since it might fail depending on server config
|
||||
@exec("php " . escapeshellarg($workerPath) . " >> " . escapeshellarg($logPath) . " 2>&1 &");
|
||||
}
|
||||
|
||||
json_success([
|
||||
'batch_id' => $batchId,
|
||||
|
||||
Reference in New Issue
Block a user