2

I created a webapp with blazor serverside with a scheduler in my app using Hangfire. It's hosted in a IIS 8.5 on windows server 2012.

I already did all the settings to make sure my blazor app dont stop and dont recycle (idle=0,startmode,Regular Time Interval...) so the sheduler is always running. And all work good.

But if there is any server reboot, i need to restart my Hangfire server to restart the sheduler inside the app (just with single ping of the url in a browser)...

enter image description here

Like we can see on the screen, the hangfire server dont start until i ping my blazor's URL in a browser...

Khalid Ab
  • 195
  • 1
  • 3
  • 17
  • This is an excellent reason *not* to use Hangfire's background job server in a web application. Host it in a Windows Service app, and host the Hangfire UI in a web app. Windows Services apps are designed to run all the time. – mason Mar 05 '21 at 18:55

2 Answers2

1

So you implemented all steps outlined in the hangfire documentation including preload and applicationInitialization?

Step 5 is persisted in the web.config of your application. To make sure it is not overwritten on deployment, one can put a web.config with the respective configuration under source control.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />

    <!-- Add this node to web.config -->
    <applicationInitialization doAppInitAfterRestart="true">

      <!-- Only needed when website contains multiple child apps -->
      <add initializationPage='/hangfire',hostname='' />

    <applicationInitialization />
  </system.webServer>
</configuration>

Finally, if you use the app_offline.htm during deployment either directly or indirectly through the Azure DevOps Pipelines deploy task, then after the app_offline.htm is removed, only the next request restarts the app. In that case you need to fire a warm-up request manually. You can use a more elaborate warm-up script or this one-liner in your deployment pipeline.

curl https://my-page.com/
-1

I think this is primarily an IIS thing, and what you want is to set the Application Pool in IIS to AlwaysRunning, so instead of starting up the worker process on the first web request it starts the worker process as soon as IIS starts.

See this SF answer

Rory
  • 40,559
  • 52
  • 175
  • 261
  • thanks for your message answer but like i said i already set the sarting mode of the application pool to AlwaysRunning :-( … What i understand is that IIS is relaunch well all application except that i need to restart my blazor app by reach the url on a browser to restart my hangfire server … :-( – Khalid Ab Mar 11 '21 at 14:06
  • Ah, ok sorry didn’t think it’d be Blazor-specific. Have you confirmed that the app pool process is running after IIS restart? (He asks...having no idea how Blazor server-side works ;) ) – Rory Mar 11 '21 at 14:25
  • 1
    Having read a little now it seems like Blazor serverside is still 'just' a .net core app, so the same rules _should_ apply. i.e. it's not really a Hangfire problem it's an ASP.NET problem. I'd start by looking at the processes/logs and confirm that your app is currently _not_ starting automatically. Assuming that's the case, you just need to solve why your .net core app doesn't start automatically. Check out https://stackoverflow.com/a/46573873/8479 for example. hth. – Rory Mar 11 '21 at 21:05
  • thanks for the link @Rory i have to try it cause actually i didn't set 'Preload Enabled' to 'true' but i don't understand what Eric mean by 'and on the website, itself, set 'Preload Enabled' to 'true' ... – Khalid Ab Mar 12 '21 at 14:46