Files
2026-09-10 15:19:17 +08:00

29 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
// Read-only poll until no prescription AI task holds a live lease (or the deadline passes).
// Prints task metadata only; no clinical content.
$serverRoot = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR;
chdir($serverRoot);
require $serverRoot . 'vendor/autoload.php';
$app = new \think\App($serverRoot);
$app->initialize();
use think\facade\Db;
$deadline = time() + (int) ($argv[1] ?? 900);
while (true) {
$now = time();
$active = Db::name('prescription_ai_task')->where('status', 'running')->where('lock_until', '>', $now)
->field('id,batch_id,model_key,attempts,started_at,progress_json')->select()->toArray();
if ($active === [] || $now >= $deadline) {
echo json_encode([
'idle' => $active === [], 'checked_at' => date('c', $now), 'active' => $active,
'tasks' => Db::name('prescription_ai_task')->field('id,batch_id,model_key,status,attempts,error_code,started_at,finished_at')->order('id')->select()->toArray(),
'results' => Db::name('prescription_ai_result')->field('id,batch_id,model_key,score,herb_score,comparison_status,comparison_reason_code,prompt_version')->select()->toArray(),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
exit($active === [] ? 0 : 1);
}
sleep(20);
}