Prototype 2 of max task length for scheduled tasks.

This commit is contained in:
Mike
2015-02-25 15:55:01 -05:00
parent 17ea0217f5
commit 5b9999eccf
11 changed files with 124 additions and 37 deletions

View File

@@ -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;
}