Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep quartz .net's scheduler alive?

I use quartz in my asp website, i initialize the scheduler in application_start method and shutdown in application_end method ,my trigger will fire everyday but I found that my scheduler will automatically shutdown if there are not request for a while ,so my background works will not triggered,are there any better way to keep the scheduler life long and only shutdown when the server stopped?

like image 355
TommyLike Avatar asked May 04 '14 05:05

TommyLike


3 Answers

For better knowledge sharing:

There are two suggestions:

  1. http://www.codeproject.com/Articles/12117/Simulate-a-Windows-Service-using-ASP-NET-to-run-sc
  2. http://weblog.west-wind.com/posts/2007/May/10/Forcing-an-ASPNET-Application-to-stay-alive
like image 120
TamerM Avatar answered Sep 19 '22 04:09

TamerM


In general, if you need reliable scheduling, you should not do it within a web site.

As you've found, the worker process will be shut down after a period of time. Even if you force the worker process to run all the time, there are conditions that may cause it to terminate as well. It's just not a good idea.

Instead, you should write a Windows Service and run quartz.net in that.

If you cannot install services (say you're in a shared hosting environment), then your options are more limited.

like image 30
Erik Funkenbusch Avatar answered Sep 20 '22 04:09

Erik Funkenbusch


There is an IIS configuration that allows worker processes to stay on all the time. I found this setting through another SO answer link.

Edit C:\Windows\System32\inetsrv\config\applicationHost.config to include:

<applicationPools> 
    <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> 
</applicationPools>

Scott Guthrie (Microsoft Product Manager for .NET) has answerered a question directly related to the OP's question (link).

@Dominic Pettifer,

If I set startMode="AlwaysRunning" does this mean the web app will 'never' shut down and will always be kept running, even with no traffic hitting the site for a long period (unless of course it's manually shut down, or server is switched off/crashes etc.)? The reason I ask is because I like to run background threads/services on the IIS ASPNET worker process instead of using Windows Services (we deal with clients with lots of security restrictions on their servers which makes running a Windows Service difficalt or impossible). Normally I have to devise something that hits the website periodically to keep the ASPNET worker process alive and stop it from shutting down.

This should mean that the application and worker process is always running - so I think that does indeed handle your scenario well for you.

Hope this helps,

Scott

like image 31
John Lee Avatar answered Sep 21 '22 04:09

John Lee