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); }
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); }
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); }
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)); }
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); }
public async Task <bool> CancelRecurringTask(RecurringTask recurringTask) { return(await CancelTask(recurringTask.TaskKey)); }