protected override async Task ExecuteAsync(CancellationToken cancellationToken) { await Task.Yield(); while (!cancellationToken.IsCancellationRequested) { try { _options = _optionsMonitor.CurrentValue; _client = _connectionService.GetClient(); _sic = _connectionService.GetServiceContent(); _props = _connectionService.GetProps(); _tasksPending = false; using (var scope = _serviceProvider.CreateScope()) { _dbContext = scope.ServiceProvider.GetRequiredService <VmContext>(); await processTasks(); } } catch (Exception ex) { _logger.LogError(ex, "Exception in TaskService"); } var intervalMilliseconds = _tasksPending ? _options.ReCheckTaskProgressIntervalMilliseconds : _options.CheckTaskProgressIntervalMilliseconds; _taskServiceHealthCheck.CompletedRun(); await _resetEvent.WaitAsync(new TimeSpan(0, 0, 0, 0, intervalMilliseconds)); } }
public ConnectionService( IOptionsMonitor <VsphereOptions> vsphereOptionsMonitor, ILogger <ConnectionService> logger, IServiceProvider serviceProvider, ConnectionServiceHealthCheck connectionServiceHealthCheck ) { _options = vsphereOptionsMonitor.CurrentValue; _optionsMonitor = vsphereOptionsMonitor; _logger = logger; _serviceProvider = serviceProvider; _connectionServiceHealthCheck = connectionServiceHealthCheck; _connectionServiceHealthCheck.HealthAllowance = _options.HealthAllowanceSeconds; }
protected override async Task ExecuteAsync(CancellationToken cancellationToken) { await Task.Yield(); int count = 0; while (!cancellationToken.IsCancellationRequested) { try { _logger.LogInformation($"Starting Connect Loop at {DateTime.UtcNow}"); _options = _optionsMonitor.CurrentValue; await Connect(); if (count == _options.LoadCacheAfterIterations) { count = 0; } if (count == 0 || _forceReload) { lock (_lock) { _forceReload = false; count = 0; } await LoadCache(); } _logger.LogInformation($"Finished Connect Loop at {DateTime.UtcNow} with {_machineCache.Count()} Machines"); } catch (Exception ex) { _logger.LogError(ex, "Exception encountered in ConnectionService loop"); count = 0; } _connectionServiceHealthCheck.CompletedRun(); await _resetEvent.WaitAsync(new TimeSpan(0, 0, _options.ConnectionRetryIntervalSeconds)); count++; } }
public Handler( IVmService vmService, IMapper mapper, IVsphereService vsphereService, ILogger <Get> logger, VsphereOptions vsphereOptions, IPrincipal user, IPlayerApiClient playerClient, IPlayerService playerService, IPermissionsService permissionsService) : base(mapper, vsphereService, playerService, user, permissionsService, vmService) { _vmService = vmService; _mapper = mapper; _vsphereService = vsphereService; _logger = logger; _vsphereOptions = vsphereOptions; _user = user as ClaimsPrincipal; _playerClient = playerClient; }
private void InitScope(IServiceScope scope) { _dbContext = scope.ServiceProvider.GetRequiredService <VmContext>(); _vsphereService = scope.ServiceProvider.GetRequiredService <IVsphereService>(); _options = _optionsMonitor.CurrentValue; }