Example #1
0
        public static void AddOrUpdate <T>(
            string recurringJobName,
            Expression <Func <T, Task> > methodCall,
            string cronExpression,
            RecurringJobOptions options)
        {
            var job = Job.FromExpression(methodCall);

            Instance.Value.AddOrUpdate(recurringJobName, job, cronExpression, options);
        }
Example #2
0
        public void AddOrUpdate(string recurringJobName, Job job, string cronExpression, RecurringJobOptions options)
        {
            if (recurringJobName == null)
            {
                throw new ArgumentNullException(nameof(recurringJobName));
            }
            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);

            _storage.CreateOrUpdateRecurringTask(new ScheduledTask()
            {
                Cron           = cronExpression,
                LastInvocation = DateTime.UtcNow,
                Name           = recurringJobName,
                NextInvocation = CrontabSchedule.Parse(cronExpression).GetNextOccurrence(DateTime.UtcNow),
                Job            = new QueueJob()
                {
                    Job         = job,
                    QueueName   = options.QueueName,
                    MaxRetries  = options.MaxRetries,
                    ContextId   = options.ContextId,
                    Description = options.Description
                },
                OnlyIfLastFinishedOrFailed = options.OnlyIfLastFinishedOrFailed
            });
        }