Trim added to LogProvider.

TrimLogsJob added to trim the logs every 24 hours.
pull/3113/head
Mark McDowall 13 years ago
parent 76114cf778
commit b02c7066ad

@ -222,5 +222,28 @@ namespace NzbDrone.Core.Test.ProviderTests
logs.Items.Should().HaveCount(50);
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 @@ namespace NzbDrone.Core
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
Kernel.Bind<IJob>().To<AppUpdateJob>().InSingletonScope();
Kernel.Bind<IJob>().To<TrimLogsJob>().InSingletonScope();
Kernel.Get<JobProvider>().Initialize();
Kernel.Get<WebTimer>().StartTimer(30);

@ -46,5 +46,11 @@ namespace NzbDrone.Core.Instrumentation
_database.Delete<Log>("");
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");
}
}
}

@ -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…
Cancel
Save