Skip to content

Commit

Permalink
added error handling to check instance status
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimChegulov committed Jan 31, 2025
1 parent aab2c6e commit 38c4e8f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions common/ASC.Core.Common/Hosting/ActivePassiveBackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,22 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var registerInstanceService = serviceScope.ServiceProvider.GetService<IRegisterInstanceManager<T>>();
var workerOptions = serviceScope.ServiceProvider.GetService<IOptions<InstanceWorkerOptions<T>>>().Value;

if (!await registerInstanceService.IsActive())
const int millisecondsDelay = 1000;
try
{
logger.TraceActivePassiveBackgroundServiceIsNotActive(serviceName, workerOptions.InstanceId);

await Task.Delay(1000, stoppingToken);
if (!await registerInstanceService.IsActive())
{
logger.TraceActivePassiveBackgroundServiceIsNotActive(serviceName, workerOptions.InstanceId);

await Task.Delay(millisecondsDelay, stoppingToken);
continue;
}
}
catch (Exception e)
{
logger.WarningWithException(e);

await Task.Delay(millisecondsDelay, stoppingToken);
continue;
}

Expand All @@ -62,6 +72,5 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

await Task.Delay(ExecuteTaskPeriod, stoppingToken);
}

}
}

0 comments on commit 38c4e8f

Please sign in to comment.