Hangfire recurring job stops after app pool gets recycle
Asked Answered
C

1

6

I have ASP.NET Core API (v 2.2) running under IIS using Windows Hosting module that is shipped with .NET Core. I have configured Hangfire in startup.cs with couple of recurring jobs.

The API's app pool periodically gets recycled because of inactivity. However whenever app pool get recycled(for any reason) the recurring job stops running until the first user invoke the api.

Hangfire documentation has solution but it is specific to Full .NET and it may not work for .NET Core.

One of the solution i found is to run recurring jobs in console application but then i have to create and maintain one more application. Also, in addition to recurring jobs, API internally creates background jobs to make one way call. For example

[HttpPost]
public IActionResult DoWork(int id)
{
    BackgroundJob.Enqueue<IWorkerService>(x => x.DoWork(id));
}

So if i create console application just for recurring jobs, i still have to configure Hangfire in API for background jobs. I am trying to avoid configuring Hangfire in two places.

What are my options in ASP.NET Core to make API always running?

UPDATE 1
based on discussion here i made the changes to App Pool settings

set Regular Time Interval to 0

enter image description here

Change Idle Time-Out from default 20 to 0 enter image description here

I will wait for few days to see how this settings works

However, i am not sure if its a good idea not to recycle app pool ever? Any suggestion

Careful answered 12/7, 2019 at 16:14 Comment(1)
if you are hosting in azure app service, set the app to always running, if in iis, you can set similarly as well to keep the app always running to ensure scheduled jobs are triggeredPostimpressionism
P
0

Ideally, you should follow the official docs.

In your case, you should also set the Managed pipeline mode to Integrated, the Start Mode to Always Running, the Preload Enabled to true, and also some edits in the Configuration Editor.

All these are mentioned and better detailed in the official docs (linked above).

Placable answered 7/9, 2020 at 8:54 Comment(1)
yeap. this worksPostimpressionism

© 2022 - 2024 — McMap. All rights reserved.