feat: 优化节点信息存储

This commit is contained in:
augushong
2025-08-23 23:24:45 +08:00
parent a9d1429000
commit 4d2a264df1

View File

@@ -23,7 +23,8 @@ class HostServiceBase
public static function getNodeId(): string
{
// 定义一个持久化存储ID的文件路径 (runtime目录在部署时通常是可写的)
$idFilePath = PathTools::tempBuildPath('node_id.lock');
$idFilePath = App::getRootPath(). 'runtime/node_id.lock';
PathTools::intiDir($idFilePath);
// 1. 如果ID文件已存在直接读取并返回
if (file_exists($idFilePath)) {
@@ -55,7 +56,7 @@ class HostServiceBase
*/
public static function heartbeat()
{
$nodeId = self::getNodeId();
$nodeId = static::getNodeId();
if (empty($nodeId)) {
Log::error('无法获取当前节点ID心跳更新失败');
@@ -65,7 +66,7 @@ class HostServiceBase
try {
$host = SystemHost::where('node_id', $nodeId)->find();
$data = self::collectHostInfo();
$data = static::collectHostInfo();
if (empty($host)) {
$host = new SystemHost();
// 首次注册