예제 #1
0
        public async Task <RecurringTask> AddRecurringTask(Expression <Action> action, string crontab, string taskName)
        {
            var recurringTask = new RecurringTask(action.ToTaskInfo(), crontab, RecurringTaskKey(taskName));

            if (await RecurringTaskDoesNotExistOrNeedsChange(recurringTask))
            {
                await EnqueueRecurringTask(recurringTask);
            }

            return(recurringTask);
        }
예제 #2
0
        public async Task <RecurringTask> AddRecurringTask(Expression <Action> action, TimeSpan interval, string taskName)
        {
            var recurringTask = new RecurringTask(action.ToTaskInfo(), interval, RecurringTaskKey(taskName));

            if (await RecurringTaskDoesNotExistOrNeedsChange(recurringTask))
            {
                await EnqueueRecurringTask(recurringTask);

                return(recurringTask);
            }

            return(null);
        }
예제 #3
0
        private async Task EnqueueRecurringTask(RecurringTask recurringTask)
        {
            var serializedTaskInfo = JsonTaskInfoSerializer.Serialize(recurringTask.TaskInfo);
            await _taskQueue.Backend.SetMapFields(ScheduledTasksMapKey,
                                                  (recurringTask.TaskKey, serializedTaskInfo),
                                                  ($"isRecurring::{recurringTask.TaskKey}", true),
                                                  ($"serializedRecurringTask::{recurringTask.TaskKey}", JsonTaskInfoSerializer.Serialize(recurringTask)));

            var nextRunTimestamp = recurringTask.GetNextRunTimestamp(recurringTask.StartTime);

            await _taskQueue.Backend.AddToOrderedSet(
                ScheduledTasksOrderedSetKey,
                nextRunTimestamp,
                recurringTask.TaskKey);
        }
예제 #4
0
        public bool IsEquivalent(RecurringTask comparisonRecurringTask)
        {
            if (comparisonRecurringTask == null)
            {
                throw new ArgumentException("comparisonRecurringTask must not be null");
            }

            if (comparisonRecurringTask.TaskKey != TaskKey)
            {
                throw new Exception("Cannot compare with a recurringTask with a different TaskKey.");
            }

            return(TaskInfo.IsEquivalent(comparisonRecurringTask.TaskInfo) &&
                   Interval == comparisonRecurringTask.Interval &&
                   string.Equals(Crontab, comparisonRecurringTask.Crontab, StringComparison.Ordinal));
        }
예제 #5
0
        private async Task <bool> RecurringTaskDoesNotExistOrNeedsChange(RecurringTask recurringTask)
        {
            var deserializedRecurringTask = await GetRecurringTask(recurringTask.TaskKey);

            if (deserializedRecurringTask == null)
            {
                return(true);
            }

            if (!recurringTask.IsEquivalent(deserializedRecurringTask))
            {
                return(true);
            }

            return(false);
        }
예제 #6
0
 public async Task <bool> CancelRecurringTask(RecurringTask recurringTask)
 {
     return(await CancelTask(recurringTask.TaskKey));
 }