feat: 看起来效果不错.

This commit is contained in:
2025-01-11 02:35:39 +08:00
parent 66a0a2de08
commit 9ed913b15d
6 changed files with 372 additions and 87 deletions
+24 -3
View File
@@ -1,6 +1,7 @@
using System.Buffers.Text;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Proxd_man.Config;
@@ -73,7 +74,10 @@ public class SubscribeManager
_logger.LogWarning(e, "更新订阅失败: {subscribeName}", subscribe.Name);
}
newSubscribeOutbounds[subscribe] = outbounds;
if (outbounds.Count > 0)
{
newSubscribeOutbounds[subscribe] = outbounds;
}
_logger.LogInformation("订阅 {subscribeName} 更新完成. (共 {outboundCount} 个节点)", subscribe.Name, outbounds.Count);
}
@@ -94,14 +98,30 @@ public class SubscribeManager
public void StartUpdateSubscribes()
{
if (_cts != null)
{
StopUpdateSubscribes();
}
var cts = new CancellationTokenSource();
Task.Run(async () =>
{
while (!cts.IsCancellationRequested)
while (!cts.Token.IsCancellationRequested)
{
if (_subscribeOutbounds.Count > 0)
{
_logger.LogDebug("订阅更新完成, 将在 12 小时后再次更新.");
await Task.Delay(TimeSpan.FromHours(12), cts.Token);
}
else
{
_logger.LogDebug("没有可用的订阅, 将在 5 分钟后再次更新.");
await Task.Delay(TimeSpan.FromMinutes(5), cts.Token);
}
_logger.LogInformation("开始更新订阅...");
await CheckAndUpdateSubscribes(cts.Token);
await Task.Delay(TimeSpan.FromHours(12), cts.Token);
}
}, cts.Token);
_cts = cts;
@@ -111,6 +131,7 @@ public class SubscribeManager
public void StopUpdateSubscribes()
{
_cts?.Cancel();
_cts = null;
}
}