2013-09-18 05:28:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Housekeeping
|
|
|
|
|
{
|
2013-09-18 19:15:12 +00:00
|
|
|
|
public class HousekeepingService : IExecute<HousekeepingCommand>
|
2013-09-18 05:28:05 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IEnumerable<IHousekeepingTask> _housekeepers;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public HousekeepingService(IEnumerable<IHousekeepingTask> housekeepers, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_housekeepers = housekeepers;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(HousekeepingCommand message)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Running housecleaning tasks");
|
|
|
|
|
|
|
|
|
|
foreach (var housekeeper in _housekeepers)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
housekeeper.Clean();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error running housekeeping task: " + housekeeper.GetType().FullName, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|