diff options
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; } |
