Skip to content

Commit

Permalink
增加环境变量配置
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Dec 16, 2024
1 parent 7439081 commit 3d242ed
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ public sealed class AutoChannelDetectionBackgroundTask(
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
// 启动一分钟后开始执行,防止卡住启动
await Task.Delay(TimeSpan.FromSeconds(60), stoppingToken);
{
// 获取环境变量是否启用自动检测通道
var autoChannelDetection = Environment.GetEnvironmentVariable("AutoChannelDetection");

if (autoChannelDetection?.ToLower() == "false")
{
logger.LogInformation("AutoChannelDetectionBackgroundTask: AutoChannelDetection is not enabled");
return;
}

// 启动一分钟后开始执行,防止卡住启动
await Task.Delay(TimeSpan.FromSeconds(60), stoppingToken);

await Task.Factory.StartNew(() => AutoHandleExceptionChannelAsync(stoppingToken), stoppingToken,
await Task.Factory.StartNew(() => AutoHandleExceptionChannelAsync(stoppingToken), stoppingToken,
TaskCreationOptions.LongRunning, TaskScheduler.Default);

while (!stoppingToken.IsCancellationRequested)
Expand Down Expand Up @@ -76,7 +85,6 @@ private async Task AutoHandleExceptionChannelAsync(CancellationToken stoppingTok
try
{
foreach (var channel in await dbContext.Channels
.AsNoTracking()
.AsNoTracking()
.Where(x => x.ControlAutomatically && x.Disable)
.ToArrayAsync(cancellationToken: stoppingToken))
Expand Down

0 comments on commit 3d242ed

Please sign in to comment.