2011-04-22 02:23:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Caching;
|
|
|
|
|
using NLog;
|
2011-04-22 05:46:47 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2011-04-22 02:23:31 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
|
|
|
|
class WebTimer
|
|
|
|
|
{
|
2011-04-22 05:46:47 +00:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-04-22 02:23:31 +00:00
|
|
|
|
|
|
|
|
|
private static CacheItemRemovedCallback _onCacheRemove;
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-04-22 05:46:47 +00:00
|
|
|
|
public WebTimer(JobProvider jobProvider)
|
|
|
|
|
{
|
|
|
|
|
_jobProvider = jobProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 02:23:31 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2011-04-22 05:46:47 +00:00
|
|
|
|
_jobProvider.RunScheduled();
|
2011-04-22 02:23:31 +00:00
|
|
|
|
StartTimer(Convert.ToInt32(v));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|