Add hangfire

This commit is contained in:
2016-02-22 09:55:57 -05:00
parent c2562949ec
commit 7a45225c29
4 changed files with 125 additions and 1 deletions
+9 -1
View File
@@ -1,4 +1,5 @@
using System.Web.Optimization;
using System;
using System.Web.Optimization;
using System.Web.Mvc;
using System.Web.Routing;
using LeafWeb.Core.DAL;
@@ -16,6 +17,13 @@ namespace LeafWeb.Web
BootstrapEditorTemplatesConfig.RegisterBundles();
DataService.RegisterInitializer();
HangfireBootstrapper.Instance.Start();
}
protected void Application_End(object sender, EventArgs e)
{
HangfireBootstrapper.Instance.Stop();
}
}
}
+89
View File
@@ -0,0 +1,89 @@
using System.Web.Hosting;
using Hangfire;
using Microsoft.Owin;
using LeafWeb.Web;
using Owin;
[assembly: OwinStartup(typeof(Startup))]
namespace LeafWeb.Web
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//GlobalConfiguration.Configuration
// .UseSqlServerStorage("LeafWebContext");
app.UseHangfireDashboard();
app.UseHangfireServer();
SetupRecurringJobs();
}
private void SetupRecurringJobs()
{
//RecurringJob.AddOrUpdate<ServiceReminderEmailService>(
// "serviceReminderJob", s => s.SendAllNotificationEmails(), Cron.Weekly(DayOfWeek.Monday, 6));
}
}
// http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html
public class ApplicationPreload : IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
HangfireBootstrapper.Instance.Start();
}
}
public class HangfireBootstrapper : IRegisteredObject
{
public static readonly HangfireBootstrapper Instance = new HangfireBootstrapper();
private readonly object _lockObject = new object();
private bool _started;
private BackgroundJobServer _backgroundJobServer;
private HangfireBootstrapper()
{
}
public void Start()
{
lock (_lockObject)
{
if (_started) return;
_started = true;
HostingEnvironment.RegisterObject(this);
GlobalConfiguration
.Configuration
.UseSqlServerStorage("LeafWebContext");
// Specify other options here
_backgroundJobServer = new BackgroundJobServer();
}
}
public void Stop()
{
lock (_lockObject)
{
if (_backgroundJobServer != null)
{
_backgroundJobServer.Dispose();
}
HostingEnvironment.UnregisterObject(this);
}
}
void IRegisteredObject.Stop(bool immediate)
{
Stop();
}
}
}
+21
View File
@@ -65,11 +65,27 @@
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Hangfire.Core, Version=1.5.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hangfire.Core.1.5.3\lib\net45\Hangfire.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Hangfire.SqlServer, Version=1.5.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hangfire.SqlServer.1.5.3\lib\net45\Hangfire.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MarkdownDeep, Version=1.5.4615.26275, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MarkdownDeep.Full.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
<Private>True</Private>
@@ -86,6 +102,10 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Web.DataVisualization" />
<Reference Include="System.Web.DynamicData" />
@@ -901,6 +921,7 @@
</Compile>
<Compile Include="Attributes\HttpParamActionAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Startup.cs" />
<Compile Include="Utility\MarkdownHelper.cs" />
<Compile Include="Utility\Validation.cs" />
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
+6
View File
@@ -9,6 +9,9 @@
<package id="bootstrap.less" version="3.3.6" targetFramework="net45" />
<package id="Bootstrap.MVC.EditorTemplates" version="1.2.0" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="Hangfire" version="1.5.3" targetFramework="net45" />
<package id="Hangfire.Core" version="1.5.3" targetFramework="net45" />
<package id="Hangfire.SqlServer" version="1.5.3" targetFramework="net45" />
<package id="jQuery" version="1.9.1" targetFramework="net45" />
<package id="jquery.validate.unobtrusive.bootstrap" version="1.2.3" targetFramework="net45" />
<package id="jQuery.Validation" version="1.14.0" targetFramework="net45" />
@@ -22,8 +25,11 @@
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Twitter.Bootstrap.Less" version="3.3.6" targetFramework="net45" />
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
</packages>