feat(update): update the backend like nodes via quadlet restart [CI]
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful

This commit is contained in:
justme committed 2026-10-18 00:36:38 +08:00
1 parent 34190f5a04
commit 68c7113adf
23 files changed
+309 -357

No files matched your search

@@ -48,6 +48,7 @@ public static class BackendHost
services.AddSingleton<IGeoLookup>(new HttpGeoLookup(options.GeoLookupUrl));
}
services.AddSingleton<IBackendRestart, HostBackendRestart>();
services.AddMoShiroApplication(options);
services.AddMoShiroGateway();
services.AddMoShiroApi();
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using MoShiro.Backend.Application;
namespace MoShiro.Backend;
/// <summary>更新确认之后让 Backend 有序退出:晚一会儿再停,先把确认请求的响应送出去。外面的 Quadlet 单元(<c>Restart=always</c>、<c>Pull=always</c>)会拉最新镜像再启动。</summary>
public sealed class HostBackendRestart : IBackendRestart
{
private static readonly TimeSpan s_delay = TimeSpan.FromSeconds(1);
private readonly IHostApplicationLifetime _lifetime;
private readonly TimeProvider _time;
public HostBackendRestart(IHostApplicationLifetime lifetime, TimeProvider time)
{
_lifetime = lifetime;
_time = time;
}
public void Request() =>
_ = Task.Run(async () =>
{
await Task.Delay(s_delay, _time);
_lifetime.StopApplication();
});
}