/// <summary> /// Executes a number of task in a sequential fashion, one after the other. /// </summary> /// <param name="backgroundTaskScheduler">The scheduler on which to enqueue tasks.</param> /// <param name="tasks">The tasks that should be scheduled.</param> /// <param name="options">Options used to determine in what state the task should be considered for execution.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation, returning the <strong>final</strong> scheduled background task.</returns> public static IScheduledBackgroundTask EnqueueSequentially( this IBackgroundTaskScheduler backgroundTaskScheduler, IEnumerable <IBackgroundTask> tasks, BackgroundTaskContinuationOptions options = BackgroundTaskContinuationOptions.OnlyOnSucceededState) { IScheduledBackgroundTask scheduledTask = null; foreach (var taskToRun in tasks) { scheduledTask = scheduledTask == null? backgroundTaskScheduler.Enqueue(taskToRun) : scheduledTask.ContinueWith(taskToRun, options); } return(scheduledTask); }
/// <inheritdoc /> public IScheduledBackgroundTask ContinueWith(IBackgroundTask backgroundTask, BackgroundTaskContinuationOptions options = BackgroundTaskContinuationOptions.OnlyOnSucceededState) { if (this._children == null) { this._children = new List <ChildScheduledBackgroundTask>(); } // Copy over the metadata from this parent task, as we know this must have been executed in the // same context as this one. var backgroundTaskEnvelope = new BackgroundTaskEnvelope(backgroundTask) { Headers = this._taskEnvelope.Headers, }; var scheduledBackgroundTask = new ChildScheduledBackgroundTask(backgroundTaskEnvelope, options, this._scheduler); this._children.Add(scheduledBackgroundTask); return(scheduledBackgroundTask); }
public ChildScheduledBackgroundTask(BackgroundTaskEnvelope taskEnvelope, BackgroundTaskContinuationOptions option, BackgroundTaskScheduler scheduler) { this._taskEnvelope = taskEnvelope; this._option = option; this._scheduler = scheduler; }
/// <inheritdoc /> public Task <string> EnqueueChildAsync(BackgroundTaskEnvelope task, string parentId, BackgroundTaskContinuationOptions continuationOptions) { var hangfireOptions = continuationOptions == BackgroundTaskContinuationOptions.OnlyOnSucceededState ? JobContinuationOptions.OnlyOnSucceededState : JobContinuationOptions.OnAnyFinishedState; return(Task.FromResult(this.CreateCore( task, queue => new AwaitingState(parentId, new EnqueuedState(queue), hangfireOptions)))); }
/// <inheritdoc /> /// <remarks> /// This method will set the request ID and baggage from the current ambient <see cref="Activity" /> on to the /// background task. /// </remarks> public Task <string> EnqueueChildAsync(BackgroundTaskEnvelope task, string parentId, BackgroundTaskContinuationOptions continuationOptions) { return(this.TrackAsync(task, () => this._innerProvider.EnqueueChildAsync(task, parentId, continuationOptions))); }