问题
To sum up the text below: What do I have to do to run Hangfire jobs when there are no users on my web page?
Im running asp net core and have started using Hangfire for recurring tasks on my web application. I left it running on my job for the weekend but when I get back no jobs has been run. After googling a bit I've got that it seems to be a "fix"/method for this on hangfires docs, but it seems to be made for non-core. Do I need a special handling for this in .Net Core (with app.UseHangFireServer() and so on?
回答1:
The problem is that your website and hangfire will only wake up after a refresh of the website by pressing F5 in the browser.
I was having the same issue for our .NET core webservice that I fixed as follows.
- Our IIS version : 7.5
- Our Server : Windows Server 2008 R2
1) You will need the so called Application Initializer which you can download here: https://www.iis.net/downloads/microsoft/application-initialization Download and run the MSI. Once installed, you will probably have to reboot the server.
2) Open applicationHost.config which is at %WINDIR%\system32\inetsrv\config in Notepad, being sure to run it with the “Run as Administrator” option. Do not use Notepad++ see: https://serverfault.com/a/599865.
3) Find the configuration section, and then look for the application pool running your gallery. If you don’t know the pool name, look it up in IIS Manager by right-clicking the application node in the left pane and choosing Manage Application > Advanced Settings. Add startMode=”AlwaysRunning” so that it looks like this:
<add name="OGF.Home.Webapi" autoStart="true" managedRuntimeVersion="" startMode="AlwaysRunning" >
4) Scroll down a little more in applicationHost.config to the configuration element. Find the entry for the gallery application and add preloadEnabled="true" , like this:
<site name="OGF.Home.Webapi" id="10" serverAutoStart="true">
<application path="/" applicationPool="OGF.Home.Webapi" preloadEnabled="true">
...
5) Restart IIS by executing iisreset in a command prompt running as an administrator.
For Windows Server 2012 and higher you can configure these settings directly in IIS by opening the "Advanced Settings" menu for the application pool and the website after installing the Application Initializer.
来源:https://stackoverflow.com/questions/55684032/hangfire-jobs-not-running-on-my-asp-net-core-site