Quartz.NET scheduler doesn't fire jobs/triggers once deployed

半世苍凉 提交于 2019-11-27 13:46:43
LeftyX

One thing that I have noticed is the use of the Scheduler in your asp.net application.
You should use singleton objects.

in your process.aspx.cs this line

IScheduler scheduler = new StdSchedulerFactory().GetScheduler();

creates a new scheduler but you should use the one you've created as static in Application_Start.

If you want to get access to the singleton instance use a public memeber in your Global.asax.cs:

 public static ISchedulerFactory SchedulerFactory;
 public static IScheduler Scheduler;

and you can reference it in your process.aspx.cs:

MvcApplication.Scheduler.ScheduleJob(job, triggersSet, true);

Another solution is to use dependency injection. You can find some info here using StructureMap and here for Unity.

UPDATE:

You can download a sample application (asp.net 4.0) called AspNet_Quartz here and see how it works here.

The problem is related to IIS rather than the schedulers Quartz.NET, Hangfire, etc. On the other hand, there are lots of solution methods posted on the web, but only some of them is working. In my opinion, there is no need to apply lots of configuration settings. Just install Keep Alive Service For IIS 6.0/7.5 on the server to which you publish your application and enjoy. After that, your published application will be alive after application pool recycling, IIS/Application restarting, etc. Hope this helps...

There are nothing wrong with Quartz, all because of IIS app pool recycling. I fixed the bug by stopping the pool that is used for Quartz from recycling:
1. Go to IIS manager -> Application Pools -> Create a new pool, I named it Scheduler (u can named anything)
2. Select Scheduler pool -> advanced Settings
+ In General section, at Start Mode, Select AlwaysRunning (IIS 8.5) or true for (IIS 7.5, 8)
+ In Process Model Section-> Idle Timeout(minutes) set to 0 (meaning: No Idel timeout)
+ In Recycling section -> Regular time Interval set to 0 (meaning: no recycling)
3. Deploy your Quartz site into that application pool. And send one request to the pool to "wake your app up" and it will run until u stop it.


That's it.
Updated: Another solution to keep your app pool always alive is using Auto-Start ASP.NET Applications

I just ran into a similar issue that might bite someone else - it brought me to this SO question after turning on debug and getting that 'batch acquisition of 0 triggers' message.
I had a job that was every 2 hours like this:

"0 0 0/2 * * ?"

And I wanted to make it more often, so every 2 minutes like this:

"0 0/2 0 * ?"

I even tried https://cronexpressiondescriptor.azurewebsites.net/ which gave me a big clue I should have read more carefully: Every 2 hours, on day 0 of the month which eventually made me realize what I really meant was:

"0 0/2 * * ?"

So the lesson was, when 'shifting left' your cron, back-fill with *, not 0.

Hope that helps someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!