10cd2986cf
Add nlog, PiscalQueueManager modified: Core.Tests/Remote/PiscalSshClientTests.cs modified: Core/DAL/DataService.cs modified: Core/Remote/IPiscalClient.cs modified: Core/Remote/PiscalSshClient.cs new file: Web/Attributes/ActionLogAttribute.cs modified: Web/Controllers/ControllerBase.cs modified: Web/Controllers/LeafInputController.cs modified: Web/Controllers/LeafOutputController.cs new file: Web/NLog.config new file: Web/NLog.xsd new file: Web/Services/PiscalQueueManager.cs modified: Web/Services/PiscalService.cs modified: Web/Startup.cs modified: Web/Web.csproj modified: Web/packages.config Ignore logs Organize piscal queue manager modified: Core/Entities/LeafInputFile.cs modified: Web/Controllers/LeafInputController.cs renamed: Web/Startup.cs -> Web/HangfireStartup.cs modified: Web/Services/PiscalQueueManager.cs modified: Web/Web.csproj cleanup usings in leafinputcontroller
94 lines
1.9 KiB
C#
94 lines
1.9 KiB
C#
using System.Web.Hosting;
|
|
using Hangfire;
|
|
using Microsoft.Owin;
|
|
using LeafWeb.Web;
|
|
using LeafWeb.Web.Services;
|
|
using Owin;
|
|
|
|
[assembly: OwinStartup(typeof(HangfireStartup))]
|
|
|
|
namespace LeafWeb.Web
|
|
{
|
|
public class HangfireStartup
|
|
{
|
|
private const string PiscalProcessQueue = "PiscalProcessQueue";
|
|
|
|
public void Configuration(IAppBuilder app)
|
|
{
|
|
//GlobalConfiguration.Configuration
|
|
// .UseSqlServerStorage("LeafWebContext");
|
|
|
|
app.UseHangfireDashboard();
|
|
app.UseHangfireServer();
|
|
|
|
SetupRecurringJobs();
|
|
}
|
|
|
|
private void SetupRecurringJobs()
|
|
{
|
|
// TODO: new SqlServerDistributedLock
|
|
RecurringJob.AddOrUpdate<PiscalQueueManager>(PiscalProcessQueue, p => p.ProcessQueue(), Cron.Minutely());
|
|
}
|
|
|
|
public static void TriggerPiscalProcessQueue()
|
|
{
|
|
RecurringJob.Trigger(PiscalProcessQueue);
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
{
|
|
_backgroundJobServer?.Dispose();
|
|
|
|
HostingEnvironment.UnregisterObject(this);
|
|
}
|
|
}
|
|
|
|
void IRegisteredObject.Stop(bool immediate)
|
|
{
|
|
Stop();
|
|
}
|
|
}
|
|
} |