public async Task <DateTime?> Execute(DateTime?lastRunTime) { logger.LogDebug("Executing automatic light control..."); var currentTime = DateTime.Now; if (!scheduleProvider.TransitionRequired(currentTime, lastRunTime)) { logger.LogDebug("No transition to perform."); await lightManager.Refresh(currentTime); return(currentTime); } await ExecuteTransition(currentTime, lastRunTime); return(currentTime); }
protected async override Task ExecuteAsync(CancellationToken cancellationToken) { var pollingFrequency = Math.Max(appOptionsDelegate.CurrentValue.PollingFrequency * 1000, appOptionsDelegate.CurrentValue.StandardTransitionTime); await lightManager.Refresh(DateTime.Now); lightManager.PrintAll(); while (!cancellationToken.IsCancellationRequested) { try { await lightScheduler.RunAsync(); await Task.Delay(pollingFrequency, cancellationToken); } catch (Exception e) { logger.LogError(e, "RunAsync failed. Retrying..."); } } }