private static async Task HandleSettingChangeAsyncIntnl(this IRecurringJobManager recurringJobManager, ISettingsManager settingsManager, ObjectSettingChangedEvent message) { foreach (var changedEntry in message.ChangedEntries.Where(x => x.EntryState == EntryState.Modified || x.EntryState == EntryState.Added)) { if (_observedSettingsDict.TryGetValue(changedEntry.NewEntry.Name, out var settingCronJob)) { await recurringJobManager.RunOrRemoveJobAsync(settingsManager, settingCronJob); } } }
/// <summary> /// use SettingCronJobBuilder for preparing SettingCronJob /// </summary> /// <param name="recurringJobManager"></param> /// <param name="settingsManager"></param> /// <param name="settingCronJob"></param> /// <returns></returns> public static Task WatchJobSettingAsync(this IRecurringJobManager recurringJobManager, ISettingsManager settingsManager, SettingCronJob settingCronJob) { if (recurringJobManager == null) { throw new ArgumentNullException(nameof(recurringJobManager)); } if (settingsManager == null) { throw new ArgumentNullException(nameof(settingsManager)); } _observedSettingsDict.AddOrUpdate(settingCronJob.EnableSetting.Name, settingCronJob, (settingName, сronJob) => settingCronJob); _observedSettingsDict.AddOrUpdate(settingCronJob.CronSetting.Name, settingCronJob, (settingName, сronJob) => settingCronJob); return(recurringJobManager.RunOrRemoveJobAsync(settingsManager, settingCronJob)); }