runShipUpdateCommand(); }); // 每三天执行一次船舶信息更新 // 3天 = 3 * 24 * 60 * 60 = 259200秒 // Timer::add(259200, function() { // $this->runShipUpdateCommand(); // }); // // // 启动时也执行一次,确保有数据 // $this->runShipUpdateCommand(); // // Log::info('船舶信息更新调度器已启动'); } /** * 执行船舶信息更新命令 */ private function runShipUpdateCommand() { try { Log::info('开始执行船舶信息更新任务'); $command = new UpdateShipInfoCommand(); $input = new ArrayInput([]); $output = new BufferedOutput(); $exitCode = $command->run($input, $output); if ($exitCode === 0) { Log::info('船舶信息更新任务执行成功: ' . $output->fetch()); } else { Log::error('船舶信息更新任务执行失败: ' . $output->fetch()); } } catch (\Exception $e) { Log::error('船舶信息更新任务执行异常', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } } }