private async void TimerRefreshFromWebApi_Elapsed(object sender, ElapsedEventArgs e) { try { logger.Trace(string.Format("WebApi refresh at {0}", DateTime.Now.ToString("o"))); List <string> activeJobs = new List <string>(); var result = await webapi.LoadBackupConfigurations(); if (result != null) { foreach (var item in result) { try { string jobId = $"{item.Id}";// _{Convert.ToBase64String(item.RowVersion)}"; if (item.IsActive.Value) { //RecurringJob. var recJob = JobStorage.Current.GetMonitoringApi().JobDetails(jobId); //RecurringJob.AddOrUpdate(jobId, () => LanCopyFileJob(item), item.Crontab); if (recJob == null) { RecurringJob.AddOrUpdate(jobId, () => DoCopyJob(item), item.Crontab); } activeJobs.Add(jobId); RecurringJob.Trigger(jobId); } else { //stopping inactive var recJob = JobStorage.Current.GetMonitoringApi().JobDetails(jobId); if (recJob != null) { RecurringJob.RemoveIfExists(jobId); } } } catch (Exception ex) { logger.Error($"Reccuring jobs refresh failed: {ex}"); //report error to webAPI webapi.LogActivity(item.Id, $"Reccuring jobs refresh failed -({item.Id})- see Err", ex.Message, "ERR"); } } } //TODO - purge ofphan jobs //JobStorage.Current.GetMonitoringApi().PurgeOrfanJobsExceptList(activeJobs); } catch (Exception ex) { logger.Error($"ERR WebApi refresh: {ex}"); //report error to webAPI webapi.LogActivity(string.Empty, "Reccuring jobs refresh final failed - see Err", ex.Message, "ERR"); } }