Fix bot things

This commit is contained in:
2025-02-07 16:54:42 +07:00
parent cd797711c1
commit 898ff85eed
8 changed files with 86 additions and 86 deletions

View File

@@ -31,25 +31,36 @@ namespace Managing.Domain.Bots
public async Task InitWorker(Func<Task> action)
{
await Task.Run(async () =>
try
{
while (Status == BotStatus.Up)
await Task.Run(async () =>
{
try
while (Status == BotStatus.Up && !CancellationToken.IsCancellationRequested)
{
await action();
try
{
await action();
ExecutionCount++;
await Task.Delay(Interval, CancellationToken.Token);
if (CancellationToken.IsCancellationRequested)
break;
}
catch (TaskCanceledException) when (CancellationToken.IsCancellationRequested)
{
// Graceful shutdown when cancellation is requested
break;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
ExecutionCount++;
await Task.Delay(Interval, CancellationToken.Token);
if (CancellationToken.IsCancellationRequested)
break;
}
}, CancellationToken.Token);
}, CancellationToken.Token);
}
catch (TaskCanceledException)
{
Console.WriteLine();
}
}
public void Stop()