Skip to content

Commit c6b476c

Browse files
committed
optimize CrontabWatcher
1 parent dd6697a commit c6b476c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabWatcher.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3131

3232
while (!stoppingToken.IsCancellationRequested)
3333
{
34-
var isLocked = await locker.LockAsync(DIST_KEY, async () =>
34+
try
3535
{
36-
await RunCronChecker(scope.ServiceProvider);
37-
await Task.Delay(1000, stoppingToken);
38-
});
39-
40-
if (!isLocked)
41-
{
42-
await Task.Delay(1000, stoppingToken);
36+
var isLocked = await locker.LockAsync(DIST_KEY, async () =>
37+
{
38+
await RunCronChecker(scope.ServiceProvider);
39+
await Task.Delay(1000, stoppingToken);
40+
});
41+
if (!isLocked)
42+
{
43+
await Task.Delay(1000, stoppingToken);
44+
}
45+
}
46+
catch (Exception ex)
47+
{
48+
_logger.LogWarning($"Crontab Watcher background service error: {ex.Message}");
49+
await Task.Delay(3000, stoppingToken);
4350
}
4451
}
4552

0 commit comments

Comments
 (0)