1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 18:28:19 +00:00
Sonarr/NzbDrone.Core/WebTimer.cs
kay.one fa1b287d58 JobProvider now stores last execution and success
JobProvider is now wired working
Job view ui is updated
2011-04-21 22:46:47 -07:00

40 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
}
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.RunScheduled();
StartTimer(Convert.ToInt32(v));
}
}
}