setName('assistant-service:daily')->setDescription('固化上海今日联系计划并复核来源状态;不调用模型或发送消息') ->addOption('once', null, Option::VALUE_NONE, '只检查一轮') ->addOption('sleep', null, Option::VALUE_REQUIRED, '检查轮询间隔秒数', '60'); } protected function execute(Input $input, Output $output): int { $running = true; if (function_exists('pcntl_async_signals')) { pcntl_async_signals(true); pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; }); pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; }); } $pause = max(1, min(60, (int) $input->getOption('sleep'))); $planner = new AssistantServiceDailyContact(); do { $result = $planner->tick(); $output->writeln('ASSISTANT_SERVICE_DAILY state=' . $result['state'] . ' scanned=' . $result['scanned'] . ' created=' . $result['created'] . ' exempted=' . $result['exempted']); if ($result['state'] === 'error') { try { Db::connect()->close(); } catch (\Throwable $ignored) {} if ($input->getOption('once')) { return 1; } } if (!$input->getOption('once') && $running) { sleep($pause); } } while (!$input->getOption('once') && $running); return 0; } }