[fix]下发指令时需要兼容旧版本,2025年新版本使用UTC时间,其它使用本地时间。智能大石头 authored at 2025-03-25 18:40:51
diff --git "a/Stardust.Data/Entity/\345\272\224\347\224\250\345\221\275\344\273\244.Biz.cs" "b/Stardust.Data/Entity/\345\272\224\347\224\250\345\221\275\344\273\244.Biz.cs"
index 4af3f92..937353d 100644
--- "a/Stardust.Data/Entity/\345\272\224\347\224\250\345\221\275\344\273\244.Biz.cs"
+++ "b/Stardust.Data/Entity/\345\272\224\347\224\250\345\221\275\344\273\244.Biz.cs"
@@ -140,8 +140,8 @@ public partial class AppCommand : Entity<AppCommand>
Id = Id,
Command = Command,
Argument = Argument,
- Expire = Expire.Year > 2000 ? Expire.ToUniversalTime() : Expire,
- StartTime = StartTime.Year > 2000 ? StartTime.ToUniversalTime() : StartTime,
+ Expire = Expire,
+ StartTime = StartTime,
TraceId = TraceId,
};
}
diff --git "a/Stardust.Data/Nodes/\350\212\202\347\202\271\345\221\275\344\273\244.Biz.cs" "b/Stardust.Data/Nodes/\350\212\202\347\202\271\345\221\275\344\273\244.Biz.cs"
index 2dcf24d..77c2497 100644
--- "a/Stardust.Data/Nodes/\350\212\202\347\202\271\345\221\275\344\273\244.Biz.cs"
+++ "b/Stardust.Data/Nodes/\350\212\202\347\202\271\345\221\275\344\273\244.Biz.cs"
@@ -164,8 +164,8 @@ public partial class NodeCommand : Entity<NodeCommand>
Id = Id,
Command = Command,
Argument = Argument,
- Expire = Expire.Year > 2000 ? Expire.ToUniversalTime() : Expire,
- StartTime = StartTime.Year > 2000 ? StartTime.ToUniversalTime() : StartTime,
+ Expire = Expire,
+ StartTime = StartTime,
TraceId = TraceId,
};
}
diff --git a/Stardust.Server/Services/NodeService.cs b/Stardust.Server/Services/NodeService.cs
index 594e077..4d29057 100644
--- a/Stardust.Server/Services/NodeService.cs
+++ b/Stardust.Server/Services/NodeService.cs
@@ -525,7 +525,10 @@ public class NodeService
item.Times++;
item.Status = CommandStatus.处理中;
- rs.Add(item.ToModel());
+
+ var commandModel = BuildCommand(item.Node, item);
+
+ rs.Add(commandModel);
}
item.UpdateTime = DateTime.Now;
}
@@ -776,8 +779,7 @@ public class NodeService
if (model.Expire > 0) cmd.Expire = DateTime.Now.AddSeconds(model.Expire);
cmd.Insert();
- var commandModel = cmd.ToModel();
- commandModel.TraceId = DefaultSpan.Current + "";
+ var commandModel = BuildCommand(node, cmd);
//var queue = _cacheProvider.GetQueue<String>($"nodecmd:{node.Code}");
//queue.Add(commandModel.ToJson());
@@ -805,6 +807,24 @@ public class NodeService
#endregion
#region 辅助
+ private static Version _version = new(3, 1, 2025, 0103);
+ private CommandModel BuildCommand(Node node, NodeCommand cmd)
+ {
+ var model = cmd.ToModel();
+ model.TraceId = DefaultSpan.Current + "";
+
+ // 新版本使用UTC时间
+ if (!node.Version.IsNullOrEmpty() && Version.TryParse(node.Version, out var ver) && ver >= _version)
+ {
+ if (model.StartTime.Year > 2000)
+ model.StartTime = model.StartTime.ToUniversalTime();
+ if (model.Expire.Year > 2000)
+ model.Expire = model.Expire.ToUniversalTime();
+ }
+
+ return model;
+ }
+
public (JwtBuilder, Node, Exception) DecodeToken(String token, String tokenSecret)
{
if (token.IsNullOrEmpty()) throw new ArgumentNullException(nameof(token));
diff --git a/Stardust.Server/Services/RegistryService.cs b/Stardust.Server/Services/RegistryService.cs
index 29b0bd9..104050f 100644
--- a/Stardust.Server/Services/RegistryService.cs
+++ b/Stardust.Server/Services/RegistryService.cs
@@ -427,7 +427,9 @@ public class RegistryService
item.Times++;
item.Status = CommandStatus.处理中;
- rs.Add(item.ToModel());
+
+ var cmdModel = BuildCommand(item.App, item);
+ rs.Add(cmdModel);
}
item.UpdateTime = DateTime.Now;
}
@@ -461,7 +463,7 @@ public class RegistryService
cmd.Insert();
// 分发命令给该应用的所有实例
- var cmdModel = cmd.ToModel();
+ var cmdModel = BuildCommand(app, cmd);
var ts = new List<Task>();
foreach (var item in AppOnline.FindAllByApp(app.Id))
{
@@ -545,4 +547,22 @@ public class RegistryService
await Task.WhenAll(ts);
}
+
+ //private static Version _version = new(3, 1, 2025, 0103);
+ private CommandModel BuildCommand(App app, AppCommand cmd)
+ {
+ var model = cmd.ToModel();
+ model.TraceId = DefaultSpan.Current + "";
+
+ // 新版本使用UTC时间
+ if (!app.Version.IsNullOrEmpty() && Version.TryParse(app.Version, out var ver) && (ver.Build < 2000 || ver.Build > 2025))
+ {
+ if (model.StartTime.Year > 2000)
+ model.StartTime = model.StartTime.ToUniversalTime();
+ if (model.Expire.Year > 2000)
+ model.Expire = model.Expire.ToUniversalTime();
+ }
+
+ return model;
+ }
}
\ No newline at end of file