NewLife/Stardust

优化应用在线的更新逻辑
智能大石头 authored at 2025-09-16 01:19:20
a8fe1eb
Tree
1 Parent(s) 293932e
Summary: 10 changed files with 26 additions and 18 deletions.
Modified +1 -1
Modified +1 -1
Modified +10 -5
Modified +4 -2
Modified +4 -4
Modified +1 -1
Modified +1 -1
Modified +1 -0
Modified +2 -2
Modified +1 -1
Modified +1 -1
diff --git a/Samples/TestA/TestA.csproj b/Samples/TestA/TestA.csproj
index 79b3809..60b2e3e 100644
--- a/Samples/TestA/TestA.csproj
+++ b/Samples/TestA/TestA.csproj
@@ -18,7 +18,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="NewLife.Core" Version="11.6.2025.901" />
+    <PackageReference Include="NewLife.Core" Version="11.6.2025.914-beta0534" />
   </ItemGroup>
 
 </Project>
Modified +1 -1
diff --git a/Samples/TestB/TestB.csproj b/Samples/TestB/TestB.csproj
index 2bdc7c3..3059ce1 100644
--- a/Samples/TestB/TestB.csproj
+++ b/Samples/TestB/TestB.csproj
@@ -18,7 +18,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="NewLife.Core" Version="11.6.2025.901" />
+    <PackageReference Include="NewLife.Core" Version="11.6.2025.914-beta0534" />
   </ItemGroup>
 
 </Project>
Modified +10 -5
diff --git a/Stardust.Server/Controllers/AppController.cs b/Stardust.Server/Controllers/AppController.cs
index 6b2dd3e..ada0946 100644
--- a/Stardust.Server/Controllers/AppController.cs
+++ b/Stardust.Server/Controllers/AppController.cs
@@ -189,21 +189,24 @@ public class AppController(RegistryService registryService, ITokenService tokenS
     {
         var app = Context.Device as App ?? throw new InvalidOperationException("未登录!");
 
+        using var span = tracer?.NewSpan("cmd:Ws:Create", app.Name);
         using var session = new AppCommandSession(socket)
         {
             Code = $"{app.Name}@{Context.ClientId}",
             Log = this,
-            SetOnline = online => registryService.SetOnline(Context, online)
+            SetOnline = online => registryService.SetOnline(Context, online),
+            Tracer = tracer,
         };
         sessionManager.Add(session);
 
-        await session.WaitAsync(HttpContext, cancellationToken);
+        await session.WaitAsync(HttpContext, span, cancellationToken);
     }
 
     /// <summary>向节点发送命令。通知应用刷新配置信息和服务信息等</summary>
     /// <param name="model"></param>
     /// <param name="token">应用令牌</param>
     /// <returns></returns>
+    [AllowAnonymous]
     [HttpPost(nameof(SendCommand))]
     public Task<CommandReplyModel> SendCommand(CommandInModel model)
     {
@@ -257,7 +260,8 @@ public class AppController(RegistryService registryService, ITokenService tokenS
         var app = Context.Device as App;
         var info = GetService(model.ServiceName);
 
-        var (svc, changed) = registryService.RegisterService(app, info, model, UserHost);
+        var online = Context.Online as AppOnline;
+        var (svc, changed) = registryService.RegisterService(app, info, model, online, UserHost);
 
         // 发布消息通知消费者
         if (changed)
@@ -313,8 +317,9 @@ public class AppController(RegistryService registryService, ITokenService tokenS
         }
 
         // 节点信息
-        var olt = AppOnline.FindByClient(model.ClientId);
-        if (olt != null) svc.NodeId = olt.NodeId;
+        //var online = AppOnline.FindByClient(model.ClientId);
+        var online = Context.Online as AppOnline;
+        if (online != null) svc.NodeId = online.NodeId;
 
         // 作用域
         svc.Scope = AppRule.CheckScope(-1, UserHost, model.ClientId);
Modified +4 -2
diff --git a/Stardust.Server/Controllers/NodeController.cs b/Stardust.Server/Controllers/NodeController.cs
index f2f3c9f..1bd9999 100644
--- a/Stardust.Server/Controllers/NodeController.cs
+++ b/Stardust.Server/Controllers/NodeController.cs
@@ -268,15 +268,17 @@ public class NodeController(NodeService nodeService, ITokenService tokenService,
     {
         var node = Context.Device as Node;
 
+        using var span = tracer?.NewSpan("cmd:Ws:Create", node.Code);
         using var session = new NodeCommandSession(socket)
         {
             Code = node.Code,
             Log = this,
-            SetOnline = online => nodeService.SetOnline(Context, online)
+            SetOnline = online => nodeService.SetOnline(Context, online),
+            Tracer = tracer,
         };
         sessionManager.Add(session);
 
-        await session.WaitAsync(HttpContext, cancellationToken);
+        await session.WaitAsync(HttpContext, span, cancellationToken);
     }
 
     /// <summary>向节点发送命令。通知节点更新、安装和启停应用等</summary>
Modified +4 -4
diff --git a/Stardust.Server/Services/RegistryService.cs b/Stardust.Server/Services/RegistryService.cs
index 0b43f78..93c2313 100644
--- a/Stardust.Server/Services/RegistryService.cs
+++ b/Stardust.Server/Services/RegistryService.cs
@@ -203,7 +203,7 @@ public class RegistryService(AppQueueService queue, AppOnlineService appOnline, 
     #endregion
 
     #region 服务注册
-    public (AppService, Boolean changed) RegisterService(App app, Service service, PublishServiceInfo model, String ip)
+    public (AppService, Boolean changed) RegisterService(App app, Service service, PublishServiceInfo model, AppOnline online, String ip)
     {
         var clientId = model.ClientId;
         var localIp = clientId;
@@ -247,8 +247,8 @@ public class RegistryService(AppQueueService queue, AppOnlineService appOnline, 
         }
 
         // 节点信息
-        var olt = AppOnline.FindByClient(model.ClientId);
-        if (olt != null) svc.NodeId = olt.NodeId;
+        //var online = AppOnline.FindByClient(model.ClientId);
+        if (online != null) svc.NodeId = online.NodeId;
 
         // 作用域
         if (service.UseScope)
@@ -511,7 +511,7 @@ public class RegistryService(AppQueueService queue, AppOnlineService appOnline, 
     /// <returns></returns>
     public override void SetOnline(DeviceContext context, Boolean online)
     {
-        if ((context.Online ?? GetOnline(context)) is AppOnline olt)
+        if ((GetOnline(context) ?? context.Online) is AppOnline olt)
         {
             olt.WebSocket = online;
             olt.Update();
Modified +1 -1
diff --git a/Stardust.Server/Stardust.Server.csproj b/Stardust.Server/Stardust.Server.csproj
index e532f15..34e7d15 100644
--- a/Stardust.Server/Stardust.Server.csproj
+++ b/Stardust.Server/Stardust.Server.csproj
@@ -48,7 +48,7 @@
   <ItemGroup>
     <PackageReference Include="NewLife.IP" Version="2.3.2025.808-beta1117" />
     <PackageReference Include="NewLife.Redis" Version="6.3.2025.820-beta1830" />
-    <PackageReference Include="NewLife.Remoting.Extensions" Version="3.5.2025.901" />
+    <PackageReference Include="NewLife.Remoting.Extensions" Version="3.5.2025.915-beta1636" />
   </ItemGroup>
 
   <ItemGroup>
Modified +1 -1
diff --git a/Stardust.Web/Stardust.Web.csproj b/Stardust.Web/Stardust.Web.csproj
index 69a8a03..7de4e28 100644
--- a/Stardust.Web/Stardust.Web.csproj
+++ b/Stardust.Web/Stardust.Web.csproj
@@ -53,7 +53,7 @@
     <PackageReference Include="NewLife.Cube.Core" Version="6.5.2025.901" />
     <PackageReference Include="NewLife.IP" Version="2.3.2025.808-beta1117" />
     <PackageReference Include="NewLife.Redis" Version="6.3.2025.820-beta1830" />
-    <PackageReference Include="NewLife.Remoting.Extensions" Version="3.5.2025.901" />
+    <PackageReference Include="NewLife.Remoting.Extensions" Version="3.5.2025.915-beta1636" />
   </ItemGroup>
 
   <ItemGroup>
Modified +1 -0
diff --git a/Stardust/LocalStarClient.cs b/Stardust/LocalStarClient.cs
index b11cc24..5dde6fe 100644
--- a/Stardust/LocalStarClient.cs
+++ b/Stardust/LocalStarClient.cs
@@ -53,6 +53,7 @@ public class LocalStarClient
 
         _client = new ApiClient($"udp://127.0.0.1:{Port}")
         {
+            Name = "StarAgent",
             Timeout = 3_000,
             Log = Log,
         };
Modified +2 -2
diff --git a/Stardust/Stardust.csproj b/Stardust/Stardust.csproj
index ae9d807..95a0d52 100644
--- a/Stardust/Stardust.csproj
+++ b/Stardust/Stardust.csproj
@@ -119,10 +119,10 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="NewLife.Remoting" Version="3.5.2025.901" />
+    <PackageReference Include="NewLife.Remoting" Version="3.5.2025.915-beta1636" />
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="NewLife.Core" Version="11.6.2025.901" />
+    <PackageReference Include="NewLife.Core" Version="11.6.2025.914-beta0534" />
   </ItemGroup>
 
 </Project>
Modified +1 -1
diff --git a/Test/Test.csproj b/Test/Test.csproj
index 7c74ed3..a69a984 100644
--- a/Test/Test.csproj
+++ b/Test/Test.csproj
@@ -33,7 +33,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="NewLife.Core" Version="11.6.2025.901" />
+    <PackageReference Include="NewLife.Core" Version="11.6.2025.914-beta0534" />
   </ItemGroup>
 
   <ItemGroup>