Files
zyt/artifacts/prescription-ai-runtime/inspect_progress_environment.php
T
2026-09-10 15:19:17 +08:00

25 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
$root = dirname(__DIR__, 2) . '/server/';
chdir($root);
require $root . 'vendor/autoload.php';
$app = new \think\App($root);
$app->initialize();
try {
$connection = (string) config('database.default');
$cfg = (array) config('database.connections.' . $connection);
$safe = [
'local_database' => in_array((string) ($cfg['hostname'] ?? ''), ['127.0.0.1', 'localhost', '::1'], true),
'table_prefix_valid' => preg_match('/^[a-zA-Z0-9_]*$/D', (string) ($cfg['prefix'] ?? '')) === 1,
'progress_column_present' => isset(\think\facade\Db::name('prescription_ai_task')->getFields()['progress_json']),
'running_models' => \think\facade\Db::name('prescription_ai_task')->where('status', 'running')->field('model_key,COUNT(*) AS count')->group('model_key')->select()->toArray(),
'active_preparation_count' => \think\facade\Db::name('prescription_ai_batch')->where('lock_until', '>', time())->count(),
'active_batch_count' => \think\facade\Db::name('prescription_ai_batch')->where('validity', 'current')->whereIn('status', ['preparing', 'waiting_sources', 'queued', 'running', 'retry_wait'])->count(),
'active_task_count' => \think\facade\Db::name('prescription_ai_task')->whereIn('status', ['queued', 'running', 'retry_wait'])->count(),
];
echo json_encode($safe, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), PHP_EOL;
} catch (\Throwable $e) {
echo json_encode(['error' => get_class($e)]), PHP_EOL;
exit(1);
}