1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 18:42:42 +01:00
Radarr/NzbDrone.Core/WebTimer.cs
2011-11-03 16:23:54 -07:00

39 lines
1.1 KiB
C#

using System;
using System.Web;
using System.Web.Caching;
using NLog;
using NzbDrone.Core.Providers.Jobs;
namespace NzbDrone.Core
{
class WebTimer
{
private readonly JobProvider _jobProvider;
private static CacheItemRemovedCallback _onCacheRemove;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public WebTimer(JobProvider jobProvider)
{
_jobProvider = jobProvider;
}
//TODO: Make timer doesn't keep running during unit tests.
public void StartTimer(int secondInterval)
{
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
HttpRuntime.Cache.Insert(GetType().ToString(), secondInterval, null,
DateTime.Now.AddSeconds(secondInterval), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
public void DoWork(string k, object v, CacheItemRemovedReason r)
{
_jobProvider.QueueScheduled();
StartTimer(Convert.ToInt32(v));
}
}
}