Example #1
0
 /// <summary>
 /// Gets job data from storage associated with <see cref="RecurringJob"/>.
 /// </summary>
 /// <param name="context">The <see cref="PerformContext"/>.</param>
 /// <returns>The job data from storage.</returns>
 public static IDictionary <string, object> GetJobData(this PerformContext context)
 {
     using (var storage = new RecurringJobInfoStorage(context.Connection))
     {
         return(storage.FindByJobId(context.BackgroundJob.Id)?.JobData);
     }
 }
        /// <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);
            }
        }
Example #3
0
        /// <summary>
        /// Persists job data to storage associated with <see cref="RecurringJob"/>.
        /// </summary>
        /// <param name="context">The <see cref="PerformContext"/>.</param>
        /// <param name="jobData">The dictionary value to be added or updated. </param>
        public static void SetJobData(this PerformContext context, IDictionary <string, object> jobData)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            using (var storage = new RecurringJobInfoStorage(context.Connection))
            {
                var recurringJobInfo = storage.FindByJobId(context.BackgroundJob.Id);

                if (recurringJobInfo.JobData == null)
                {
                    recurringJobInfo.JobData = new Dictionary <string, object>();
                }

                foreach (var kv in jobData)
                {
                    recurringJobInfo.JobData[kv.Key] = kv.Value;
                }

                storage.SetJobData(recurringJobInfo);
            }
        }