$check ? 'array' : ($source['CACHE_STORE'] ?? 'file'), 'PGOPTIONS' => $check ? '-c default_transaction_read_only=on' : '', 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '', 'LOG_CHANNEL' => 'stderr'] as $key => $value) { putenv($key.'='.$value); $_ENV[$key] = $_SERVER[$key] = $value; } $app = require $root.'/bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); app(StandaloneRuntime::class)->assertLoadedPackages(); if (! app(RequisitionExpiry::class)->ready()) { throw new LogicException('Approval deadline capability unavailable.'); } if ($check) { if (DB::selectOne('SHOW default_transaction_read_only')->default_transaction_read_only !== 'on') { throw new LogicException('Deadline task preflight must be read-only.'); } echo json_encode(['state' => 'ready', 'database_enforced_read_only' => true, 'installation_verified' => true, 'pending_requests_with_configured_cycle_policy' => DB::table('requisitions')->where('status', 'pending')->whereNotNull('approval_snapshot->approval_expiry')->count(), 'business_commands' => false, 'task_installed_or_started' => false], JSON_THROW_ON_ERROR).PHP_EOL; exit; } $lock = fopen($root.'/storage/framework/approval-deadlines-evaluation.lock', 'c'); if ($lock === false) { throw new RuntimeException('Deadline task lock unavailable.'); } if (! flock($lock, LOCK_EX | LOCK_NB)) { fclose($lock); exit(0); } $status = ['started_at' => gmdate('c'), 'result' => 'running', 'scope' => 'Compras pilot 8005 approval deadlines']; $statusPath = $root.'/storage/framework/approval-deadlines-status.json'; $save = static function (array $state) use ($statusPath): void { $temporary = $statusPath.'.'.bin2hex(random_bytes(4)).'.tmp'; file_put_contents($temporary, json_encode($state, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); if (! rename($temporary, $statusPath)) { throw new RuntimeException('Deadline task status unavailable.'); } }; try { $save($status); $exitCode = Artisan::call('sgc:approval-deadlines-tick'); $status += ['finished_at' => gmdate('c'), 'exit_code' => $exitCode]; $status['result'] = $exitCode === 0 ? 'passed' : 'retry_pending'; $save($status); } finally { flock($lock, LOCK_UN); fclose($lock); } echo json_encode($status, JSON_THROW_ON_ERROR).PHP_EOL; exit($exitCode);