commit
435e50fd9a
|
@ -1,8 +1,7 @@
|
|||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -24,51 +23,15 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
/// </summary>
|
||||
public class ScheduledTaskWorker : IScheduledTaskWorker
|
||||
{
|
||||
/// <summary>
|
||||
/// The options for the json Serializer.
|
||||
/// </summary>
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application paths.
|
||||
/// </summary>
|
||||
/// <value>The application paths.</value>
|
||||
private readonly IApplicationPaths _applicationPaths;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the logger.
|
||||
/// </summary>
|
||||
/// <value>The logger.</value>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the task manager.
|
||||
/// </summary>
|
||||
/// <value>The task manager.</value>
|
||||
private readonly ITaskManager _taskManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _last execution result sync lock.
|
||||
/// </summary>
|
||||
private readonly object _lastExecutionResultSyncLock = new object();
|
||||
|
||||
private bool _readFromFile = false;
|
||||
|
||||
/// <summary>
|
||||
/// The _last execution result.
|
||||
/// </summary>
|
||||
private readonly object _lastExecutionResultSyncLock = new();
|
||||
private bool _readFromFile;
|
||||
private TaskResult _lastExecutionResult;
|
||||
|
||||
private Task _currentTask;
|
||||
|
||||
/// <summary>
|
||||
/// The _triggers.
|
||||
/// </summary>
|
||||
private Tuple<TaskTriggerInfo, ITaskTrigger>[] _triggers;
|
||||
|
||||
/// <summary>
|
||||
/// The _id.
|
||||
/// </summary>
|
||||
private string _id;
|
||||
|
||||
/// <summary>
|
||||
|
@ -104,18 +67,13 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
InitTriggerEvents();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<GenericEventArgs<double>> TaskProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scheduled task.
|
||||
/// </summary>
|
||||
/// <value>The scheduled task.</value>
|
||||
/// <inheritdoc />
|
||||
public IScheduledTask ScheduledTask { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last execution result.
|
||||
/// </summary>
|
||||
/// <value>The last execution result.</value>
|
||||
/// <inheritdoc />
|
||||
public TaskResult LastExecutionResult
|
||||
{
|
||||
get
|
||||
|
@ -169,22 +127,13 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
/// <inheritdoc />
|
||||
public string Name => ScheduledTask.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
/// <inheritdoc />
|
||||
public string Description => ScheduledTask.Description;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category.
|
||||
/// </summary>
|
||||
/// <value>The category.</value>
|
||||
/// <inheritdoc />
|
||||
public string Category => ScheduledTask.Category;
|
||||
|
||||
/// <summary>
|
||||
|
@ -199,10 +148,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
/// <value>The current execution start time.</value>
|
||||
private DateTime CurrentExecutionStartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the state.
|
||||
/// </summary>
|
||||
/// <value>The state.</value>
|
||||
/// <inheritdoc />
|
||||
public TaskState State
|
||||
{
|
||||
get
|
||||
|
@ -218,10 +164,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current progress.
|
||||
/// </summary>
|
||||
/// <value>The current progress.</value>
|
||||
/// <inheritdoc />
|
||||
public double? CurrentProgress { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -247,12 +190,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <value>The triggers.</value>
|
||||
/// <exception cref="ArgumentNullException"><c>value</c> is <c>null</c>.</exception>
|
||||
public TaskTriggerInfo[] Triggers
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<TaskTriggerInfo> Triggers
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -272,10 +211,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique id.
|
||||
/// </summary>
|
||||
/// <value>The unique id.</value>
|
||||
/// <inheritdoc />
|
||||
public string Id
|
||||
{
|
||||
get
|
||||
|
@ -290,6 +226,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
ReloadTriggerEvents(true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ReloadTriggerEvents()
|
||||
{
|
||||
ReloadTriggerEvents(false);
|
||||
|
@ -529,14 +466,14 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
catch
|
||||
{
|
||||
return new TaskTriggerInfo[]
|
||||
{
|
||||
new TaskTriggerInfo
|
||||
return
|
||||
[
|
||||
new()
|
||||
{
|
||||
IntervalTicks = TimeSpan.FromDays(1).Ticks,
|
||||
Type = TaskTriggerInfo.TriggerInterval
|
||||
}
|
||||
};
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,9 +526,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
((TaskManager)_taskManager).OnTaskCompleted(this, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
@ -41,21 +39,16 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
ScheduledTasks = Array.Empty<IScheduledTaskWorker>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<GenericEventArgs<IScheduledTaskWorker>>? TaskExecuting;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<TaskCompletionEventArgs>? TaskCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of Scheduled Tasks.
|
||||
/// </summary>
|
||||
/// <value>The scheduled tasks.</value>
|
||||
public IScheduledTaskWorker[] ScheduledTasks { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IScheduledTaskWorker> ScheduledTasks { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cancels if running and queue.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The task type.</typeparam>
|
||||
/// <param name="options">Task options.</param>
|
||||
/// <inheritdoc />
|
||||
public void CancelIfRunningAndQueue<T>(TaskOptions options)
|
||||
where T : IScheduledTask
|
||||
{
|
||||
|
@ -65,16 +58,14 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
QueueScheduledTask<T>(options);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CancelIfRunningAndQueue<T>()
|
||||
where T : IScheduledTask
|
||||
{
|
||||
CancelIfRunningAndQueue<T>(new TaskOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels if running.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The task type.</typeparam>
|
||||
/// <inheritdoc />
|
||||
public void CancelIfRunning<T>()
|
||||
where T : IScheduledTask
|
||||
{
|
||||
|
@ -82,11 +73,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
((ScheduledTaskWorker)task).CancelIfRunning();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues the scheduled task.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The task type.</typeparam>
|
||||
/// <param name="options">Task options.</param>
|
||||
/// <inheritdoc />
|
||||
public void QueueScheduledTask<T>(TaskOptions options)
|
||||
where T : IScheduledTask
|
||||
{
|
||||
|
@ -102,12 +89,14 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void QueueScheduledTask<T>()
|
||||
where T : IScheduledTask
|
||||
{
|
||||
QueueScheduledTask<T>(new TaskOptions());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void QueueIfNotRunning<T>()
|
||||
where T : IScheduledTask
|
||||
{
|
||||
|
@ -119,6 +108,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Execute<T>()
|
||||
where T : IScheduledTask
|
||||
{
|
||||
|
@ -144,11 +134,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues the scheduled task.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="options">The task options.</param>
|
||||
/// <inheritdoc />
|
||||
public void QueueScheduledTask(IScheduledTask task, TaskOptions options)
|
||||
{
|
||||
var scheduledTask = ScheduledTasks.FirstOrDefault(t => t.ScheduledTask.GetType() == task.GetType());
|
||||
|
@ -186,10 +172,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the tasks.
|
||||
/// </summary>
|
||||
/// <param name="tasks">The tasks.</param>
|
||||
/// <inheritdoc />
|
||||
public void AddTasks(IEnumerable<IScheduledTask> tasks)
|
||||
{
|
||||
var list = tasks.Select(t => new ScheduledTaskWorker(t, _applicationPaths, this, _logger));
|
||||
|
@ -197,9 +180,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
ScheduledTasks = ScheduledTasks.Concat(list).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
@ -218,11 +199,13 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Cancel(IScheduledTaskWorker task)
|
||||
{
|
||||
((ScheduledTaskWorker)task).Cancel();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task Execute(IScheduledTaskWorker task, TaskOptions options)
|
||||
{
|
||||
return ((ScheduledTaskWorker)task).Execute(options);
|
||||
|
|
|
@ -142,7 +142,7 @@ public partial class AudioNormalizationTask : IScheduledTask
|
|||
continue;
|
||||
}
|
||||
|
||||
t.LUFS = await CalculateLUFSAsync(string.Format(CultureInfo.InvariantCulture, "-i \"{0}\"", t.Path.Replace("\"", "\\\"", StringComparison.Ordinal)), cancellationToken);
|
||||
t.LUFS = await CalculateLUFSAsync(string.Format(CultureInfo.InvariantCulture, "-i \"{0}\"", t.Path.Replace("\"", "\\\"", StringComparison.Ordinal)), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_itemRepository.SaveItems(tracks, cancellationToken);
|
||||
|
|
|
@ -36,13 +36,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChapterImagesTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>.
|
||||
/// <param name="libraryManager">The library manager.</param>.
|
||||
/// <param name="itemRepo">The item repository.</param>
|
||||
/// <param name="appPaths">The application paths.</param>
|
||||
/// <param name="encodingManager">The encoding manager.</param>
|
||||
/// <param name="fileSystem">The filesystem.</param>
|
||||
/// <param name="localization">The localization manager.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="itemRepo">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="appPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||
/// <param name="encodingManager">Instance of the <see cref="IEncodingManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
public ChapterImagesTask(
|
||||
ILogger<ChapterImagesTask> logger,
|
||||
ILibraryManager libraryManager,
|
||||
|
@ -76,15 +76,15 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
new TaskTriggerInfo
|
||||
{
|
||||
Type = TaskTriggerInfo.TriggerDaily,
|
||||
TimeOfDayTicks = TimeSpan.FromHours(2).Ticks,
|
||||
MaxRuntimeTicks = TimeSpan.FromHours(4).Ticks
|
||||
}
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -92,14 +92,14 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
{
|
||||
var videos = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
MediaTypes = new[] { MediaType.Video },
|
||||
MediaTypes = [MediaType.Video],
|
||||
IsFolder = false,
|
||||
Recursive = true,
|
||||
DtoOptions = new DtoOptions(false)
|
||||
{
|
||||
EnableImages = false
|
||||
},
|
||||
SourceTypes = new SourceType[] { SourceType.Library },
|
||||
SourceTypes = [SourceType.Library],
|
||||
IsVirtualItem = false
|
||||
})
|
||||
.OfType<Video>()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
@ -72,7 +71,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return Enumerable.Empty<TaskTriggerInfo>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ public class CleanupCollectionAndPlaylistPathsTask : IScheduledTask
|
|||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
/// <param name="collectionManager">Instance of the <see cref="ICollectionManager"/> interface.</param>
|
||||
/// <param name="playlistManager">Instance of the <see cref="IPlaylistManager"/> interface.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="providerManager">The provider manager.</param>
|
||||
/// <param name="fileSystem">The filesystem.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
public CleanupCollectionAndPlaylistPathsTask(
|
||||
ILocalizationManager localization,
|
||||
ICollectionManager collectionManager,
|
||||
|
@ -135,6 +135,6 @@ public class CleanupCollectionAndPlaylistPathsTask : IScheduledTask
|
|||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[] { new TaskTriggerInfo() { Type = TaskTriggerInfo.TriggerStartup } };
|
||||
return [new TaskTriggerInfo() { Type = TaskTriggerInfo.TriggerStartup }];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,17 +67,14 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public bool IsLogged => true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
// Every so often
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteLogFileTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="localization">The localization manager.</param>
|
||||
/// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
public DeleteLogFileTask(IConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization)
|
||||
{
|
||||
_configurationManager = configurationManager;
|
||||
|
@ -57,16 +57,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public bool IsLogged => true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -65,8 +65,8 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
new TaskTriggerInfo
|
||||
{
|
||||
Type = TaskTriggerInfo.TriggerStartup
|
||||
|
@ -76,7 +76,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
Type = TaskTriggerInfo.TriggerInterval,
|
||||
IntervalTicks = TimeSpan.FromHours(24).Ticks
|
||||
}
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -22,9 +22,9 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptimizeDatabaseTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="localization">The localization manager.</param>
|
||||
/// <param name="provider">The jellyfin DB context provider.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
/// <param name="provider">Instance of the <see cref="IDbContextFactory{JellyfinDbContext}"/> interface.</param>
|
||||
public OptimizeDatabaseTask(
|
||||
ILogger<OptimizeDatabaseTask> logger,
|
||||
ILocalizationManager localization,
|
||||
|
@ -56,17 +56,14 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public bool IsLogged => true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
// Every so often
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -13,37 +11,41 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <summary>
|
||||
/// Class PeopleValidationTask.
|
||||
/// </summary>
|
||||
public class PeopleValidationTask : IScheduledTask
|
||||
public class PeopleValidationTask : IScheduledTask, IConfigurableScheduledTask
|
||||
{
|
||||
/// <summary>
|
||||
/// The library manager.
|
||||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly ILocalizationManager _localization;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PeopleValidationTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="libraryManager">The library manager.</param>
|
||||
/// <param name="localization">The localization manager.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
public PeopleValidationTask(ILibraryManager libraryManager, ILocalizationManager localization)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_localization = localization;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name => _localization.GetLocalizedString("TaskRefreshPeople");
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Description => _localization.GetLocalizedString("TaskRefreshPeopleDescription");
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Category => _localization.GetLocalizedString("TasksLibraryCategory");
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => "RefreshPeople";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsHidden => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnabled => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsLogged => true;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -19,14 +17,17 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// </summary>
|
||||
public class PluginUpdateTask : IScheduledTask, IConfigurableScheduledTask
|
||||
{
|
||||
/// <summary>
|
||||
/// The _logger.
|
||||
/// </summary>
|
||||
private readonly ILogger<PluginUpdateTask> _logger;
|
||||
|
||||
private readonly IInstallationManager _installationManager;
|
||||
private readonly ILocalizationManager _localization;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginUpdateTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="installationManager">Instance of the <see cref="IInstallationManager"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
public PluginUpdateTask(ILogger<PluginUpdateTask> logger, IInstallationManager installationManager, ILocalizationManager localization)
|
||||
{
|
||||
_logger = logger;
|
||||
|
@ -55,10 +56,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public bool IsLogged => true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
// At startup
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -45,10 +43,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|||
/// <inheritdoc />
|
||||
public string Key => "RefreshLibrary";
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||
{
|
||||
yield return new TaskTriggerInfo
|
||||
|
|
|
@ -25,23 +25,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
TaskOptions = taskOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [triggered].
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? Triggered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the options of this task.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public TaskOptions TaskOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Stars waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <param name="lastResult">The last result.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="taskName">The name of the task.</param>
|
||||
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
|
||||
/// <inheritdoc />
|
||||
public void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
|
||||
{
|
||||
DisposeTimer();
|
||||
|
@ -58,9 +48,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
_timer = new Timer(_ => OnTriggered(), null, dueTime, TimeSpan.FromMilliseconds(-1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void Stop()
|
||||
{
|
||||
DisposeTimer();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
|
@ -12,7 +10,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
/// </summary>
|
||||
public sealed class StartupTrigger : ITaskTrigger
|
||||
{
|
||||
public const int DelayMs = 3000;
|
||||
private const int DelayMs = 3000;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartupTrigger"/> class.
|
||||
|
@ -23,23 +21,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
TaskOptions = taskOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [triggered].
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? Triggered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the options of this task.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public TaskOptions TaskOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Stars waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <param name="lastResult">The last result.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="taskName">The name of the task.</param>
|
||||
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
|
||||
/// <inheritdoc />
|
||||
public async void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
|
||||
{
|
||||
if (isApplicationStartup)
|
||||
|
@ -50,9 +38,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
private readonly TimeSpan _timeOfDay;
|
||||
private readonly DayOfWeek _dayOfWeek;
|
||||
private Timer? _timer;
|
||||
private bool _disposed = false;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WeeklyTrigger"/> class.
|
||||
|
@ -28,23 +28,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
TaskOptions = taskOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [triggered].
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? Triggered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the options of this task.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public TaskOptions TaskOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Stars waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <param name="lastResult">The last result.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="taskName">The name of the task.</param>
|
||||
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
|
||||
/// <inheritdoc />
|
||||
public void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
|
||||
{
|
||||
DisposeTimer();
|
||||
|
@ -81,9 +71,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
|||
return triggerDate.Add(_timeOfDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops waiting for the trigger action.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void Stop()
|
||||
{
|
||||
DisposeTimer();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for configurable scheduled tasks.
|
||||
/// </summary>
|
||||
public interface IConfigurableScheduledTask
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -16,6 +17,10 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// <value><c>true</c> if this instance is enabled; otherwise, <c>false</c>.</value>
|
||||
bool IsEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is logged.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is logged; otherwise, <c>false</c>.</value>
|
||||
bool IsLogged { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Jellyfin.Data.Events;
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
|
@ -60,7 +61,7 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// Gets or sets the triggers that define when the task will run.
|
||||
/// </summary>
|
||||
/// <value>The triggers.</value>
|
||||
TaskTriggerInfo[] Triggers { get; set; }
|
||||
IReadOnlyList<TaskTriggerInfo> Triggers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique id.
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -7,17 +5,26 @@ using Jellyfin.Data.Events;
|
|||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for the TaskManager class.
|
||||
/// </summary>
|
||||
public interface ITaskManager : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Event handler for task execution.
|
||||
/// </summary>
|
||||
event EventHandler<GenericEventArgs<IScheduledTaskWorker>>? TaskExecuting;
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for task completion.
|
||||
/// </summary>
|
||||
event EventHandler<TaskCompletionEventArgs>? TaskCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of Scheduled Tasks.
|
||||
/// </summary>
|
||||
/// <value>The scheduled tasks.</value>
|
||||
IScheduledTaskWorker[] ScheduledTasks { get; }
|
||||
IReadOnlyList<IScheduledTaskWorker> ScheduledTasks { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Cancels if running and queue.
|
||||
|
@ -56,6 +63,10 @@ namespace MediaBrowser.Model.Tasks
|
|||
void QueueScheduledTask<T>()
|
||||
where T : IScheduledTask;
|
||||
|
||||
/// <summary>
|
||||
/// Queues the scheduled task if it is not already running.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
|
||||
void QueueIfNotRunning<T>()
|
||||
where T : IScheduledTask;
|
||||
|
||||
|
@ -72,10 +83,24 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// <param name="tasks">The tasks.</param>
|
||||
void AddTasks(IEnumerable<IScheduledTask> tasks);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the tasks.
|
||||
/// </summary>
|
||||
/// <param name="task">The tasks.</param>
|
||||
void Cancel(IScheduledTaskWorker task);
|
||||
|
||||
/// <summary>
|
||||
/// Executes the tasks.
|
||||
/// </summary>
|
||||
/// <param name="task">The tasks.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <returns>The executed tasks.</returns>
|
||||
Task Execute(IScheduledTaskWorker task, TaskOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Executes the tasks.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
|
||||
void Execute<T>()
|
||||
where T : IScheduledTask;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,33 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing event arguments for task completion.
|
||||
/// </summary>
|
||||
public class TaskCompletionEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TaskCompletionEventArgs"/> class.
|
||||
/// </summary>
|
||||
/// <param name="task">Instance of the <see cref="IScheduledTaskWorker"/> interface.</param>
|
||||
/// <param name="result">The task result.</param>
|
||||
public TaskCompletionEventArgs(IScheduledTaskWorker task, TaskResult result)
|
||||
{
|
||||
Task = task;
|
||||
Result = result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the task.
|
||||
/// </summary>
|
||||
/// <value>The task.</value>
|
||||
public IScheduledTaskWorker Task { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the result.
|
||||
/// </summary>
|
||||
/// <value>The result.</value>
|
||||
public TaskResult Result { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
|
@ -13,7 +14,7 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// </summary>
|
||||
public TaskInfo()
|
||||
{
|
||||
Triggers = Array.Empty<TaskTriggerInfo>();
|
||||
Triggers = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -50,7 +51,7 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// Gets or sets the triggers.
|
||||
/// </summary>
|
||||
/// <value>The triggers.</value>
|
||||
public TaskTriggerInfo[] Triggers { get; set; }
|
||||
public IReadOnlyList<TaskTriggerInfo> Triggers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description.
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing options for tasks.
|
||||
/// </summary>
|
||||
public class TaskOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum runtime in ticks.
|
||||
/// </summary>
|
||||
/// <value>The ticks.</value>
|
||||
public long? MaxRuntimeTicks { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
|
@ -10,9 +8,24 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// </summary>
|
||||
public class TaskTriggerInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The daily trigger.
|
||||
/// </summary>
|
||||
public const string TriggerDaily = "DailyTrigger";
|
||||
|
||||
/// <summary>
|
||||
/// The weekly trigger.
|
||||
/// </summary>
|
||||
public const string TriggerWeekly = "WeeklyTrigger";
|
||||
|
||||
/// <summary>
|
||||
/// The interval trigger.
|
||||
/// </summary>
|
||||
public const string TriggerInterval = "IntervalTrigger";
|
||||
|
||||
/// <summary>
|
||||
/// The startup trigger.
|
||||
/// </summary>
|
||||
public const string TriggerStartup = "StartupTrigger";
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user