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.37k stars 1.7k forks source link

Hangfire Stops After IIS App Pool Recycling #1829

Open john-larson opened 3 years ago

john-larson commented 3 years ago

I have followed the guide on https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html but still Hangfire stops after IIS app pool is recycled.

I am trying it on Windows 10 IIS with ASP.NET Core 3.1.

The application pool can be manually recycled in order to replicate the issue.

AEIsmason commented 2 years ago

Hi John, I'm having the same issue - were you able to determine a work around or fix?

I am using .NET Core 6, and IIS 8 (on a Windows Server 2012 R2).

I am trying to use Hangfire to send daily reminder emails. Hangfire is working for me when someone is using the web app - but fails if the web app isn't started by a user visiting the site.

Here is a chronological view of my problem (as I understand it now):

  1. User visits web page URL
  2. Hangfire server instance is created
  3. Hangfire server checks with SqlServer for any tasks.
  4. If there are tasks past due (for example an email to be sent), Hangfire will complete the task.
  5. The user stops using the web application
  6. The IIS Application Pool gets recycled - which causes the Hangfire server to terminate.
  7. The Application Pool restarts, but does not recreate the Hangfire server.
  8. The scheduled tasks are not triggered by Hangfire because there is no instance of a Hangfire server open.
  9. Eventually, when a user uses the web application, we return to step 1.

I think there are two options for me: A. Find a way to prevent the hangfire server from terminating. B. Find a way to auto-create a new instance of the Hangfire server after successful recycle of the IIS Application Pool.

Or, perhaps Hangfire is not right for my scenario. Also open to hear about alternative task management tools if you think they are better suited for handing scheduled tasks.

AEIsmason commented 2 years ago

One other question for you John,

When you say you followed the guide in the above link, were you able to complete the section "Create the Classes"? That piece is specific to Asp.Net and the required libraries are not supported/used in .NET Core.

From that link: "First, you’ll need a special class that implements the IProcessHostPreloadClient interface. It will be called automatically by Windows Process Activation service during its start-up and after each Application pool recycle."

I have not found an alternative in .NET Core for the above instruction.

chandusekhar commented 1 year ago

Is there any roadmap to close the issue.

BesimOznalcin commented 1 year ago

@AEIsmason @john-larson @chandusekhar

Did you find any solution about this problem?

prophellen commented 8 months ago

@AEIsmason Did you solve this or found any substitution for IProcessHostPreloadClient in .Net Core?