public void Ctor_SetTheDefaultValues_ForProperties() { var options = new RecurringJobOptions(); Assert.Equal(TimeZoneInfo.Utc, options.TimeZone); Assert.Equal("default", options.QueueName); }
private static EnforceRecurringJob Create <T>(string id, Expression <Action <T> > methodCall, string cronExpression, RecurringJobOptions options) { var job = Job.FromExpression(methodCall); return(new EnforceRecurringJob(id, job, cronExpression, options)); }
public EnforceRecurringJob(string id, Job job, string cronExpression, RecurringJobOptions recurringJobOptions) { Job = job ?? throw new ArgumentNullException(nameof(job)); CronExpression = cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)); RecurringJobOptions = recurringJobOptions ?? throw new ArgumentNullException(nameof(recurringJobOptions)); Id = id ?? throw new ArgumentNullException(nameof(id)); }
public void SetQueueName_ThrowsAnException_WhenQueueNameHasInvalidFormat() { var options = new RecurringJobOptions(); var exception = Assert.Throws<ArgumentException>( () => options.QueueName = "UPPER_CASE"); Assert.Equal("value", exception.ParamName); }
public void SetQueueName_ThrowsAnException_WhenQueueNameHasInvalidFormat() { var options = new RecurringJobOptions(); var exception = Assert.Throws <ArgumentException>( () => options.QueueName = "UPPER_CASE"); Assert.Equal("value", exception.ParamName); }
public static EnforceRecurringJob Create <T>(string id, Expression <Action <T> > methodCall, string cronExpression, string queue) { var options = new RecurringJobOptions { QueueName = queue }; return(Create(id, methodCall, cronExpression, options)); }
/// <summary>Initializes a new instance of the <see cref="HangfireJobDetail"/> class.</summary> /// <param name="id">The identifier.</param> /// <param name="job">The job.</param> /// <param name="cronExpression">The cron expression.</param> /// <param name="options">The options.</param> public HangfireJobDetail( string id, Job job, string cronExpression, RecurringJobOptions options = default) { Id = id; Job = job; CronExpression = cronExpression; Options = options; }
public override int GetHashCode() { unchecked { var hashCode = Id != null?Id.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (Job != null ? Job.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (RecurringJobOptions != null ? RecurringJobOptions.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (CronExpression != null ? CronExpression.GetHashCode() : 0); return(hashCode); } }
public static void AddOrUpdate( [NotNull] this RecurringDateRangeJobManager manager, string recurringJobId, Job job, string cronExpression, DateTime?startDate, DateTime?endDate, RecurringJobOptions options) { if (recurringJobId == null) { throw new ArgumentNullException(nameof(recurringJobId)); } if (job == null) { throw new ArgumentNullException(nameof(job)); } if (cronExpression == null) { throw new ArgumentNullException(nameof(cronExpression)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } manager.AddOrUpdate( new RecurringDateRangeJobOptions() { RecurringJobId = recurringJobId, Job = job, CronExpression = cronExpression, StartDateTime = startDate, EndDateTime = endDate, RecurringJobOptions = options }); }
public void AddOrUpdate(string recurringJobId, Job job, string cronExpression, RecurringJobOptions options) { if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); if (job == null) throw new ArgumentNullException(nameof(job)); if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); if (options == null) throw new ArgumentNullException(nameof(options)); ValidateCronExpression(cronExpression); using (var connection = _storage.GetConnection()) { var recurringJob = new Dictionary<string, string>(); var invocationData = InvocationData.Serialize(job); recurringJob["Job"] = JobHelper.ToJson(invocationData); recurringJob["Cron"] = cronExpression; recurringJob["TimeZoneId"] = options.TimeZone.Id; recurringJob["Queue"] = options.QueueName; var existingJob = connection.GetAllEntriesFromHash($"recurring-job:{recurringJobId}"); if (existingJob == null) { recurringJob["CreatedAt"] = JobHelper.SerializeDateTime(DateTime.UtcNow); } using (var transaction = connection.CreateWriteTransaction()) { transaction.SetRangeInHash( $"recurring-job:{recurringJobId}", recurringJob); transaction.AddToSet("recurring-jobs", recurringJobId); transaction.Commit(); } } }
string ITraffkRecurringJobManager.Add(Hangfire.Common.Job job, string cronExpression) { var tenantId = Finder.GetTenantIdAsync().ExecuteSynchronously(); var contactId = CurrentUser?.User?.ContactId; var recurringJobId = GetRecurringJobId(); var q = job.Method.GetCustomAttributes(false).OfType <QueueAttribute>().FirstOrDefault() ?? job.Type.GetCustomAttribute <QueueAttribute>(); var options = new RecurringJobOptions { QueueName = q?.Queue, }; RecurringJobManager.AddOrUpdate(recurringJobId, job, cronExpression, options); GDB.Hash.Add(new HangfireHash { Key = "recurring-job:" + recurringJobId, Field = "TenantId", Value = tenantId.ToString() }); if (contactId != null) { GDB.Hash.Add(new HangfireHash { Key = "recurring-job:" + recurringJobId, Field = "ContactId", Value = contactId.ToString() }); } GDB.SaveChanges(); return(recurringJobId); }
public void SetQueueName_ThrowsAnException_WhenValueIsNull() { var options = new RecurringJobOptions(); Assert.Throws<ArgumentNullException>(() => options.QueueName = null); }
public void SetQueueName_ThrowsAnException_WhenValueIsNull() { var options = new RecurringJobOptions(); Assert.Throws <ArgumentNullException>(() => options.QueueName = null); }
public void AddOrUpdate([NotNull] string recurringJobId, [NotNull] Job job, [NotNull] string cronExpression, [NotNull] RecurringJobOptions options) { cronExpression = GetCronSchedule(recurringJobId, cronExpression); this.recurringJobManager.AddOrUpdate(recurringJobId: recurringJobId, job: job, cronExpression: cronExpression, options: options); }