2021-05-20 19:28:18 +00:00
|
|
|
using System;
|
2020-10-14 17:44:11 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-11-02 01:32:41 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2020-10-14 17:44:11 +00:00
|
|
|
using MediaBrowser.Model.Activity;
|
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
using MediaBrowser.Model.Tasks;
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes old activity log entries.
|
|
|
|
/// </summary>
|
|
|
|
public class CleanActivityLogTask : IScheduledTask, IConfigurableScheduledTask
|
|
|
|
{
|
|
|
|
private readonly ILocalizationManager _localization;
|
|
|
|
private readonly IActivityManager _activityManager;
|
2020-11-02 01:32:41 +00:00
|
|
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
2020-10-14 17:44:11 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="CleanActivityLogTask"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
|
|
|
/// <param name="activityManager">Instance of the <see cref="IActivityManager"/> interface.</param>
|
2020-11-02 01:32:41 +00:00
|
|
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
2020-10-14 17:44:11 +00:00
|
|
|
public CleanActivityLogTask(
|
|
|
|
ILocalizationManager localization,
|
2020-11-02 01:32:41 +00:00
|
|
|
IActivityManager activityManager,
|
|
|
|
IServerConfigurationManager serverConfigurationManager)
|
2020-10-14 17:44:11 +00:00
|
|
|
{
|
|
|
|
_localization = localization;
|
|
|
|
_activityManager = activityManager;
|
2020-11-02 01:32:41 +00:00
|
|
|
_serverConfigurationManager = serverConfigurationManager;
|
2020-10-14 17:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public string Name => _localization.GetLocalizedString("TaskCleanActivityLog");
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public string Key => "CleanActivityLog";
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public string Description => _localization.GetLocalizedString("TaskCleanActivityLogDescription");
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory");
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool IsHidden => false;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool IsEnabled => true;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool IsLogged => true;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
|
|
|
{
|
2020-11-02 01:32:41 +00:00
|
|
|
var retentionDays = _serverConfigurationManager.Configuration.ActivityLogRetentionDays;
|
2021-09-01 22:52:59 +00:00
|
|
|
if (!retentionDays.HasValue || retentionDays < 0)
|
2020-11-02 01:32:41 +00:00
|
|
|
{
|
|
|
|
throw new Exception($"Activity Log Retention days must be at least 0. Currently: {retentionDays}");
|
|
|
|
}
|
|
|
|
|
2021-07-11 20:32:06 +00:00
|
|
|
var startDate = DateTime.UtcNow.AddDays(-retentionDays.Value);
|
2020-10-14 17:44:11 +00:00
|
|
|
return _activityManager.CleanAsync(startDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
|
|
|
{
|
|
|
|
return Enumerable.Empty<TaskTriggerInfo>();
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 19:28:18 +00:00
|
|
|
}
|