diff options
| author | Mike <github@barry.io> | 2015-02-25 15:55:01 -0500 |
|---|---|---|
| committer | Mike <github@barry.io> | 2015-02-26 09:05:12 -0500 |
| commit | 5b9999eccff26db4f285179ed0b682f46f6dad81 (patch) | |
| tree | 7bb002e460d4668e0ee2fc20b8745fe848d5d6ed /MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs | |
| parent | 17ea0217f57f4439d65edcfd2091f1bb47570438 (diff) | |
Prototype 2 of max task length for scheduled tasks.
Diffstat (limited to 'MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs')
| -rw-r--r-- | MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 4d6cc1608..78dcea493 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -313,7 +313,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> - async void trigger_Triggered(object sender, EventArgs e) + async void trigger_Triggered(object sender, GenericEventArgs<TaskExecutionOptions> e) { var trigger = (ITaskTrigger)sender; @@ -340,11 +340,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// <summary> /// Executes the task /// </summary> + /// <param name="options">Task options.</param> /// <returns>Task.</returns> /// <exception cref="System.InvalidOperationException">Cannot execute a Task that is already running</exception> - public async Task Execute() + public async Task Execute(TaskExecutionOptions options) { - var task = ExecuteInternal(); + var task = ExecuteInternal(options); _currentTask = task; @@ -358,7 +359,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks } } - private async Task ExecuteInternal() + private async Task ExecuteInternal(TaskExecutionOptions options) { // Cancel the current execution, if any if (CurrentCancellationTokenSource != null) @@ -383,7 +384,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks try { - await ExecuteTask(CurrentCancellationTokenSource.Token, progress).ConfigureAwait(false); + var localTask = ScheduledTask.Execute(CurrentCancellationTokenSource.Token, progress); + + if (options != null && options.MaxRuntimeMs.HasValue) + { + CurrentCancellationTokenSource.CancelAfter(options.MaxRuntimeMs.Value); + } + + await localTask.ConfigureAwait(false); status = TaskCompletionStatus.Completed; } |
