mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-18 06:53:07 +03:00
Prototype 2 of max task length for scheduled tasks.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user