Hello,
I am suffering to set up my web application with hangfire always running.
I followed the instruction on the document page(http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html) and red similar topics in this forum but I do not know what I did wrong.
Could you help me to set up always running properly?
First of all, my web application is using owin.
namespace ApiService.Scheduler
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
...
HangfireBootstrapper.Instance.Start();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
AuthorizationFilters = new[] { new AnonymousAuthorizationFilter() }
});
var properties = new AppProperties(app.Properties);
CancellationToken token = properties.OnAppDisposing;
if (token != CancellationToken.None)
{
token.Register(() =>
{
HangfireBootstrapper.Instance.Stop();
});
}
var manager = new RecurringJobManager();
manager.AddOrUpdate("job1", Job.FromExpression(() => CapitalClaimsJob.Run()), "*/2 7-20 * * MON-FRI", TimeZoneInfo.Local);
}
}
}
namespace ApiService.Scheduler.Infrastructure
{
public class ApplicationPreload : IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
HangfireBootstrapper.Instance.Start();
}
}
}
namespace ApiService.Scheduler.Infrastructure
{
public class HangfireBootstrapper : IRegisteredObject
{
// exactly same as document code
}
}
I changed %WINDIR%\System32\inetsrv\config\applicationHost.config like as following
<configuration>
...
<system.applicationHost>
<applicationPools>
<add name="DefaultAppPool" />
<add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
<add name=".NET v4.5" managedRuntimeVersion="v4.0" />
<add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
<add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
<add name=".NET v2.0" managedRuntimeVersion="v2.0" />
<add name="Hangfire" autoStart="true" startMode="AlwaysRunning" />
<applicationPoolDefaults managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" />
</applicationPoolDefaults>
</applicationPools>
...
<sites>
<site name="Hangfire" id="1" serverAutoStart="true">
<application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="ApplicationPreload">
<virtualDirectory path="/" physicalPath="C:\webapp\hangfire" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
...
</sites>
<serviceAutoStartProviders>
<add name="ApplicationPreload" type="ApiService.Scheduler.Infrastructure.ApplicationPreload, ApiService.Scheduler" />
</serviceAutoStartProviders>
<webLimits />
</system.applicationHost>
...
</configuration>
I made like this but every morning application is dead and I have to start recurring job manually Q.Q
Regards,