HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.43k stars 1.7k forks source link

How to keep .NET 8 Hangfire application always running on IIS? #2426

Open dedmytas opened 4 months ago

dedmytas commented 4 months ago

Hi,

I made a post on your forum: https://discuss.hangfire.io/t/how-to-keep-net-8-hangfire-application-always-running-on-iis/10806

tl;dr

I have a .NET 8 application running Hangfire and hosting on IIS. After some time the application shuts down (I'm guessing because it does not get any user input). This is really bad, because I have a scheduled task that needs to run daily.

I did everything in your documentation section to keep IIS app always running, but it does not work. documentation link I recycle / restart app pool, but application does not wake up, it only starts when I visit "/hangfire" endpoint.

How do I make this work? I've read a workaround about making a scheduled task to hit the endpoint every hour or something, but then why use Hangfire in the first place? I am trying to get rid of task scheduler tasks.

Please help.

HernJer commented 4 months ago

i have 4 instances running (DEV,QA,UAT,PROD) for over a year. The only thing i did was set IIS Start Mode = AlwaysRunning and Preload Enabled = True.

PhilipDn commented 1 month ago

The instructions in this article have worked for me: https://dotnetblog.asphostportal.com/how-to-make-sure-your-asp-net-core-keep-running-on-iis/

Note that one item mentioned in the linked article (that’s not always listed in other articles) is that you need to install the “Application Initialization Module” in Windows. In my testing, the app pool settings and enabling “Preload” were not sufficient, but after installing the “Application Initialization Module”, my ASP.NET Core application has been running unattended successfully for weeks.

PhilipDn commented 1 month ago

To summarize the article linked in my previous reply:

  1. In Server Manager on the server where you will run the Hangfire application, install the "Application Initialization" module (under "Web Server"-"Web Server"-"Application Development") [this might require a reboot].
  2. In IIS, create a new application pool for your site/application, set the .NET CLR version to v4.0, set start mode to "Always Running", and set Idle Time-Out (minutes) to 0.
  3. In IIS for your website that's running your Hangfire application, set the application pool to the one you created above, and set "Preload Enabled" to true.