refactoring

This commit is contained in:
Alexey Bannov 2022-06-21 12:57:20 +03:00
parent 72f0ac4f9b
commit b78feb8ae9
2 changed files with 18 additions and 5 deletions

View File

@ -32,17 +32,26 @@ public class RegisterInstanceWorkerService<T> : BackgroundService where T : IHos
private readonly ILogger _logger;
private readonly IHostApplicationLifetime _applicationLifetime;
private readonly IServiceProvider _serviceProvider;
private readonly int _intervalCheckRegisterInstanceInSeconds;
public static readonly string InstanceId =
$"{typeof(T).GetFormattedName()}_{DateTime.UtcNow.Ticks}";
public RegisterInstanceWorkerService(
ILogger<RegisterInstanceWorkerService<T>> logger,
IServiceProvider serviceProvider,
IHostApplicationLifetime applicationLifetime)
IHostApplicationLifetime applicationLifetime,
IConfiguration configuration)
{
_logger = logger;
_serviceProvider = serviceProvider;
_applicationLifetime = applicationLifetime;
if (!int.TryParse(configuration["core:hosting:intervalCheckRegisterInstanceInSeconds"], out _intervalCheckRegisterInstanceInSeconds))
{
_intervalCheckRegisterInstanceInSeconds = 1;
}
_intervalCheckRegisterInstanceInSeconds = _intervalCheckRegisterInstanceInSeconds*1000;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -60,7 +69,7 @@ public class RegisterInstanceWorkerService<T> : BackgroundService where T : IHos
_logger.TraceWorkingRunnging(DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
await Task.Delay(_intervalCheckRegisterInstanceInSeconds, stoppingToken);
}
catch (Exception ex)
{

View File

@ -29,7 +29,11 @@
"folder": "../../products",
"subfolder": "Server"
},
"search-by-content": false
"search-by-content": false,
"hosting": {
"intervalCheckRegisterInstanceInSeconds": "1",
"timeUntilUnregisterInSeconds": "15"
}
},
"license": {
"file": {