HangFire stops for some reason

I have a ASP.NET Core project that uses HangFire to run recurring jobs. For some reason HangFire stops after some time and logs as follows:

2022-08-11 10:42 Debug Hangfire Server is stopping...
2022-08-11 10:42 Information Server sdu-ituadev0a:8060:badc3a3e caught stopping signal...
2022-08-11 10:42 Debug Execution loop ServerWatchdog:01472bd9 stopped in 0,0718 ms
2022-08-11 10:42 Debug Execution loop RecurringJobScheduler:686f412f stopped in 0,2737 ms
2022-08-11 10:42 Debug Execution loop CountersAggregator:b9d8a1e6 stopped in 0,3949 ms
2022-08-11 10:42 Information Server sdu-ituadev0a:8060:badc3a3e caught stopped signal...
2022-08-11 10:42 Debug Execution loop ServerJobCancellationWatcher:bc51023d stopped in 2,4785 ms
2022-08-11 10:42 Debug Execution loop ExpirationManager:d7372429 stopped in 2,7121 ms
2022-08-11 10:42 Debug Execution loop SqlServerHeartbeatProcess:29d236f2 stopped in 11,5211 ms
2022-08-11 10:42 Debug Execution loop DelayedJobScheduler:534fec47 stopped in 11,6591 ms

It shuts down and then no jobs are executed and no heartbeats are sent.

I want it to run forever. What am I missing?

The application sets:

  • Preload enabled to true
  • Startmode to Always running
  • Idle timeout to 0
  • doAppInitAfterRestart to true

I currently do not set hostName and initializationPage but I invoke /hangfire after deployment.

It runs under IIS 10

Thanks in advance.

Kind regards
Søren

Unfortunately that’s just how IIS works - the site will get spun down at some point when there’s no activity, even with AlwaysRunning enabled.

You might have better results running the site under Kestrel, but I’ve not tried that yet, so I can’t offer any advice, there.

Your best bet is to set up some sort of pinging service and add an anonymous endpoint that it can hit periodically, or move the Hangfire Server to a background service - the dashboard can still be hosted in your site.

1 Like

Thanks, I will try that.

1 Like

Esta utilizando a extensao UseConsole do hangfire? Para mim foi oque funcionou…

No I use IIS and my own Web-based tail. I would not know where to make UseConsole fit in. But thanks for the input. I am about to relase a heartbeat endpoint that will be invoked by a monitoring tool. Hopefully that fixes the problem.

I have now used a monitoring tool (OP5) to call a web page in the solution for some weeks and it works perfectly.