TimerProvider will test every 1 minute to see if it matches a schedule for updating season or entire series.

Countdown now shows a real value from RSS Sync.

CentralDispatch updated to start RSSSyncTimer when run.
pull/7/merge
markus101 14 years ago
parent fd4cf86694
commit 0fc75e8907

@ -70,15 +70,21 @@ namespace NzbDrone.Core
_kernel.Bind<INotificationProvider>().To<NotificationProvider>().InSingletonScope();
_kernel.Bind<ILogProvider>().To<LogProvider>().InSingletonScope();
_kernel.Bind<IMediaFileProvider>().To<MediaFileProvider>().InSingletonScope();
_kernel.Bind<ITimerProvider>().To<TimerProvider>().InSingletonScope();
_kernel.Bind<IRepository>().ToMethod(c => new SimpleRepository(dbProvider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();
_kernel.Bind<IRepository>().ToConstant(logRepository).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
_kernel.Bind<IRepository>().ToConstant(logRepository).WhenInjectedInto<LogProvider>().InSingletonScope();
ForceMigration(_kernel.Get<IRepository>());
SetupIndexers(_kernel.Get<IRepository>()); //Setup the default set of indexers on start-up
SetupDefaultQualityProfiles(_kernel.Get<IRepository>()); //Setup the default QualityProfiles on start-up
//Get the Timers going
var config = _kernel.Get<IConfigProvider>();
var timer = _kernel.Get<ITimerProvider>();
timer.SetRssSyncTimer(Convert.ToInt32(config.GetValue("SyncFrequency", "15", true)));
timer.StartRssSyncTimer();
}
}

@ -13,5 +13,7 @@ namespace NzbDrone.Core.Providers
void SetRssSyncTimer(int minutes);
TimeSpan RssSyncTimeLeft();
DateTime NextRssSyncTime();
void StartMinuteTimer();
void StopMinuteTimer();
}
}

@ -2,27 +2,35 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
using NLog;
using NzbDrone.Core.Model.Notification;
using Timer = System.Threading.Timer;
namespace NzbDrone.Core.Providers
{
public class TimerProvider : ITimerProvider
{
private ProgressNotification _seriesSyncNotification;
private IRssSyncProvider _rssSyncProvider;
private Thread _rssSyncThread;
private System.Timers.Timer _rssSyncTimer;
private ISeriesProvider _seriesProvider;
private ISeasonProvider _seasonProvider;
private IEpisodeProvider _episodeProvider;
private Timer _rssSyncTimer;
private Timer _minuteTimer;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private DateTime _rssSyncNextInterval;
public TimerProvider(IRssSyncProvider rssSyncProvider)
public TimerProvider(IRssSyncProvider rssSyncProvider, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider)
{
_rssSyncProvider = rssSyncProvider;
_seriesProvider = seriesProvider;
_seasonProvider = seasonProvider;
_episodeProvider = episodeProvider;
_rssSyncTimer = new Timer();
_minuteTimer = new Timer(60000);
}
#region ITimerProvider Members
@ -32,15 +40,16 @@ namespace NzbDrone.Core.Providers
double interval = _rssSyncTimer.Interval;
_rssSyncTimer .Interval= interval;
}
public void StartRssSyncTimer()
{
if (_rssSyncTimer.Interval < 900000) //If Timer is less than 15 minutes, throw an error!
if (_rssSyncTimer.Interval < 900000) //If Timer is less than 15 minutes, throw an error! This should also be handled when saving the config, though a user could by-pass it by editing the DB directly... TNO (Trust No One)
{
Logger.Error("RSS Sync Frequency is invalid, please set the interval first");
throw new InvalidOperationException("RSS Sync Frequency Invalid");
}
_rssSyncTimer.Elapsed +=new ElapsedEventHandler(RunSync);
_rssSyncTimer.Elapsed +=new ElapsedEventHandler(RunRssSync);
_rssSyncTimer.Start();
_rssSyncNextInterval = DateTime.Now.AddMilliseconds(_rssSyncTimer.Interval);
}
@ -66,12 +75,51 @@ namespace NzbDrone.Core.Providers
return _rssSyncNextInterval;
}
public void StartMinuteTimer()
{
_minuteTimer.Elapsed += new ElapsedEventHandler(MinuteTimer_Elapsed);
_minuteTimer.Start();
}
public void StopMinuteTimer()
{
_minuteTimer.Stop();
}
#endregion
private void RunSync(object obj, ElapsedEventArgs args)
private void RunRssSync(object obj, ElapsedEventArgs args)
{
DateTime.Now.AddMilliseconds(_rssSyncTimer.Interval);
_rssSyncProvider.Begin();
}
private void MinuteTimer_Elapsed(object obj, ElapsedEventArgs args)
{
//Check to see if anything should be run at this time, if so run it
var now = DateTime.Now;
//Daily (Except Sunday) 03:00 - Update the lastest season for all TV Shows
if (now.Hour == 3 && now.Minute == 0 && now.DayOfWeek != DayOfWeek.Sunday)
{
foreach (var series in _seriesProvider.GetAllSeries())
{
var season = _seasonProvider.GetLatestSeason(series.SeriesId);
_episodeProvider.RefreshEpisodeInfo(season);
}
}
//Sunday 03:00 - Update all TV Shows
if (now.Hour == 3 && now.Minute == 0 && now.DayOfWeek == DayOfWeek.Sunday)
{
foreach (var series in _seriesProvider.GetAllSeries())
{
_episodeProvider.RefreshEpisodeInfo(series.SeriesId);
}
}
throw new NotImplementedException();
}
}
}

@ -3,13 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Providers;
namespace NzbDrone.Web.Controllers
{
public class SharedController : Controller
{
//
// GET: /Shared/
private ITimerProvider _timerProvider;
public SharedController(ITimerProvider timerProvider)
{
_timerProvider = timerProvider;
}
public ActionResult Index()
{
@ -19,7 +24,8 @@ namespace NzbDrone.Web.Controllers
[ChildActionOnly]
public ActionResult Footer()
{
ViewData["RssTimer"] = DateTime.Now.AddMinutes(61).AddSeconds(10).ToString("yyyyMMddHHmmss");
ViewData["RssTimer"] = _timerProvider.NextRssSyncTime().ToString("yyyyMMddHHmmss");
//ViewData["RssTimer"] = DateTime.Now.AddMinutes(61).AddSeconds(10).ToString("yyyyMMddHHmmss");
return PartialView();
}
}

Loading…
Cancel
Save