public async Task RunReportAsync(Report report) { while (true) { try { //estimate report generation time to correct interval between runnings var stopwatch = new Stopwatch(); stopwatch.Start(); await report.ExecuteAsync(); stopwatch.Stop(); Trace.WriteLine(stopwatch.Elapsed); await CoreEx.DelayIfNeeded(report.RunInterval, stopwatch.Elapsed); } catch (Exception exception) { var minutes = TimeSpan.FromMinutes(10); await SystemLogRepository.SaveAsync(exception, $"Unhandled report error. Report will be recycled in {minutes}. "); await Task.Delay(minutes); //TODO to config } } }
public async Task RunCycleAsync(Job job) { var silence = new SilenceTime(); while (true) { try { var elapsed = await RunJobAsync(job, silence); await CoreEx.DelayIfNeeded(job.CheckInterval, elapsed); } catch (Exception exception) { var minutes = TimeSpan.FromMinutes(10); await SystemLogRepository.SaveAsync(exception, $"Unhandled job error. Job = [{job.Name}]. Job will be recycled in {minutes}. "); await Task.Delay(minutes); //TODO to config } } }