mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 10:32:35 +01:00
Trim added to LogProvider.
TrimLogsJob added to trim the logs every 24 hours.
This commit is contained in:
parent
76114cf778
commit
b02c7066ad
@ -222,5 +222,28 @@ public void pagedLogs()
|
|||||||
logs.Items.Should().HaveCount(50);
|
logs.Items.Should().HaveCount(50);
|
||||||
logs.TotalItems.Should().Be(100);
|
logs.TotalItems.Should().Be(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Trim_Logs_should_clear_logs_older_than_30_days()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var historyItem = Builder<Log>.CreateListOfSize(20)
|
||||||
|
.TheFirst(10).With(c => c.Time = DateTime.Now)
|
||||||
|
.TheNext(10).With(c => c.Time = DateTime.Now.AddDays(-31))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
var db = MockLib.GetEmptyDatabase();
|
||||||
|
mocker.SetConstant(db);
|
||||||
|
|
||||||
|
db.InsertMany(historyItem);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
db.Fetch<Log>().Should().HaveCount(20);
|
||||||
|
mocker.Resolve<LogProvider>().Trim();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
db.Fetch<Log>().Should().HaveCount(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ private void InitJobs()
|
|||||||
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
|
||||||
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
||||||
Kernel.Bind<IJob>().To<AppUpdateJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<AppUpdateJob>().InSingletonScope();
|
||||||
|
Kernel.Bind<IJob>().To<TrimLogsJob>().InSingletonScope();
|
||||||
|
|
||||||
Kernel.Get<JobProvider>().Initialize();
|
Kernel.Get<JobProvider>().Initialize();
|
||||||
Kernel.Get<WebTimer>().StartTimer(30);
|
Kernel.Get<WebTimer>().StartTimer(30);
|
||||||
|
@ -46,5 +46,11 @@ public void DeleteAll()
|
|||||||
_database.Delete<Log>("");
|
_database.Delete<Log>("");
|
||||||
Logger.Info("Cleared Log History");
|
Logger.Info("Cleared Log History");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Trim()
|
||||||
|
{
|
||||||
|
_database.Delete<Log>("WHERE Time < @0", DateTime.Now.AddDays(-30).Date);
|
||||||
|
Logger.Info("Logs have been trimmed, events older than 30 days have been removed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
35
NzbDrone.Core/Providers/Jobs/TrimLogsJob.cs
Normal file
35
NzbDrone.Core/Providers/Jobs/TrimLogsJob.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Core.Instrumentation;
|
||||||
|
using NzbDrone.Core.Model.Notification;
|
||||||
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
{
|
||||||
|
public class TrimLogsJob : IJob
|
||||||
|
{
|
||||||
|
private readonly LogProvider _logProvider;
|
||||||
|
|
||||||
|
public TrimLogsJob(LogProvider logProvider)
|
||||||
|
{
|
||||||
|
_logProvider = logProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "Trim Logs Job"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DefaultInterval
|
||||||
|
{
|
||||||
|
get { return 1440; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
||||||
|
{
|
||||||
|
_logProvider.Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user