/// <summary> /// Register RecurringJob via <see cref="RecurringJobInfo"/>. /// </summary> /// <param name="recurringJobInfo"><see cref="RecurringJob"/> info.</param> public void Register(RecurringJobInfo recurringJobInfo) { if (recurringJobInfo == null) { throw new ArgumentNullException(nameof(recurringJobInfo)); } Register(recurringJobInfo.RecurringJobId, recurringJobInfo.Method, recurringJobInfo.Cron, recurringJobInfo.TimeZone, recurringJobInfo.Queue); using (var storage = new RecurringJobInfoStorage()) { storage.SetJobData(recurringJobInfo); } }
/// <summary> /// Sets <see cref="RecurringJobInfo"/> to storage which associated with <see cref="RecurringJob"/>. /// </summary> /// <param name="recurringJobInfo">The specified identifier of the RecurringJob.</param> public void SetJobData(RecurringJobInfo recurringJobInfo) { if (recurringJobInfo == null) { throw new ArgumentNullException(nameof(recurringJobInfo)); } if (recurringJobInfo.JobData == null || recurringJobInfo.JobData.Count == 0) { return; } using (_connection.AcquireDistributedLock($"recurringjobextensions-jobdata:{recurringJobInfo.RecurringJobId}", LockTimeout)) { var changedFields = new Dictionary <string, string> { [nameof(RecurringJobInfo.Enable)] = JobHelper.ToJson(recurringJobInfo.Enable), [nameof(RecurringJobInfo.JobData)] = JobHelper.ToJson(recurringJobInfo.JobData) }; _connection.SetRangeInHash($"recurring-job:{recurringJobInfo.RecurringJobId}", changedFields); } }