Quartz.net调度不火的工作/触发器一旦部署 [英] Quartz.net scheduler doesn't fire jobs/triggers once deployed

查看:521
本文介绍了Quartz.net调度不火的工作/触发器一旦部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 Quartz.Net 的上的 ASP.Net 的框架4,WebForms的网站。
基本上,用户应具有hability手动触发的批处理脚本异步处理数千个存储在数据库中的记录。用户可以停止或随时暂停,调整一些变量,并继续在需要与过程(剩余的记录)。结果
在code完成并在本地工作的(开发机,WIN7,VS2010,SQL服务器前preSS 2008 R2)。结果
它也被测试的本地服务器(服务器赢得2008 R2,SQL Server的前preSS 2008 R2)上。
它工作正常,在两个enviroments,所有的code precompiled测试。
问题是,一旦部署在远程服务器上(赢服务器2008 R2),它实际上应该(托管环境,不共享,不群集),它并不完全工作在运行(SE细节下面)。 计划得到创建,但触发的,因此这份工作,不火

I'm using Quartz.Net on an ASP.Net framework 4, webforms web site. Basically, the user should have the hability to fire manually a batch script that asynchronously processes thousands of records stored on a database. The user can stop or pause at any time, adjust some variables, and continue if needed with the process (remaining records).
The code is done and working locally (developer machine, win7, vs2010, sql server express 2008 R2).
It was also tested on a local server (win server 2008 R2, sql server express 2008 R2). It works fine on both enviroments, tested with all the code precompiled. The problem is that, once deployed on a remote server (win server 2008 R2), where it actually should be running on (hosting enviroment, not shared, not clustered), it doesnt completely works (se details below). Scheduler gets created, but the trigger, hence the job, doesn't fire.

注意:我知道你们中的一些会建议使用石英作为窗口服务,但尽管这样做的好处,我真的想找出为什么它不能作为一个工作嵌入式解决方案,因为它应该是工作就好做像本地)

(Note: I know some of you would suggest to use Quartz as windows service, but despite the benefits of doing so, I really would like to find out why it doesn't work as an embedded solution, since it should be working just fine like does locally)

Quartz 2.1.2  
Common.Logging 2.1.2  
Common.Logging.NLog 2.0.0  
NLog 2.0.1.2

的Global.asax

public static ISchedulerFactory SchedulerFactory;
public static IScheduler Scheduler;

void Application_Start(object sender, EventArgs e)
{
    SchedulerFactory = new StdSchedulerFactory();
    Scheduler = SchedulerFactory.GetScheduler();

    // Define a durable job instance (durable jobs can exist without triggers)
    IJobDetail job = JobBuilder.Create<MyJobClass>()
                                .WithIdentity("MyJob", "MyGroup")
                                .StoreDurably()
                                .Build();

    Scheduler.AddJob(job, false);
    Scheduler.Start();
}
void Application_End(object sender, EventArgs e)
{
    Scheduler.Shutdown(true);
}

process.aspx.cs (启动按钮点击)

// get records from DB, iterate, process, etc
...

IJobDetail job = ASP.global_asax.Scheduler.GetJobDetail(new JobKey("MyJob", "MyGroup"));
job.JobDataMap.Put("something1", 1);
job.JobDataMap.Put("something2", somevar);

ITrigger trigger = TriggerBuilder.Create()
                    .WithIdentity("MyTrigger", "MyGroup")
                    .StartNow()
                    .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever())
                    .Build();

var triggersSet = new Quartz.Collection.HashSet<ITrigger> { trigger };

ASP.global_asax.Scheduler.ScheduleJob(job, triggersSet, true);

日志输出

本地日志

从嵌入的资源文件中加载

LOG OUTPUT

local log

Default Quartz.NET properties loaded from embedded resource file  
Using default implementation for object serializer  
Using default implementation for ThreadExecutor  
Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl  
Quartz Scheduler v.2.1.2.400 created.  
RAMJobStore initialized.  
Scheduler meta-data: Quartz Scheduler (v2.1.2.400) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED'   Scheduler class: 'Quartz.Core.QuartzScheduler' - running locally.   NOT STARTED.   Currently in standby mode.   Number of jobs executed: 0   Using thread pool 'Quartz.Simpl.SimpleThreadPool' - with 10 threads.   Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.  
Quartz scheduler 'DefaultQuartzScheduler' initialized  
Quartz scheduler version: 2.1.2.400  
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.  
Batch acquisition of 0 triggers  
Batch acquisition of 0 triggers

它继续日志记录的批量采集0触发的,直到按一下按钮时:

It continues logging Batch acquisition of 0 triggers until button click occurs:

Default Quartz.NET properties loaded from embedded resource file  
Batch acquisition of 1 triggers  
Producing instance of Job 'MyGroup.MyJob', class=MyJobClass  
Batch acquisition of 0 triggers  
Calling Execute on job MyGroup.MyJob  
Trigger instruction : NoInstruction  
Batch acquisition of 1 triggers  
Producing instance of Job 'MyGroup.MyJob', class=MyJobClass  
Batch acquisition of 0 triggers  
Calling Execute on job MyGroup.MyJob  
Trigger instruction : NoInstruction  
Batch acquisition of 1 triggers

部署日志

从嵌入的资源文件中加载

deployed log

Default Quartz.NET properties loaded from embedded resource file  
Using default implementation for object serializer  
Using default implementation for ThreadExecutor  
Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl  
Quartz Scheduler v.2.1.2.400 created.  
RAMJobStore initialized.  
Scheduler meta-data: Quartz Scheduler (v2.1.2.400) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED' Scheduler class: 'Quartz.Core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'Quartz.Simpl.SimpleThreadPool' - with 10 threads. Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.   
Quartz scheduler 'DefaultQuartzScheduler' initialized  
Quartz scheduler version: 2.1.2.400  
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.

下面保持这个样子。正如你看到的,相对于其他的日志,它不是试图收购触发器(行的批量采集0触发的不会出现在所有)。如果你点击按钮的过程无论如何,日志添加一行:

Here stays like this. As you see, compared to the other log, it's not trying to acquire triggers (line Batch acquisition of 0 triggers does not appear at all). If you click the process button anyway, the log adds one line:

Default Quartz.NET properties loaded from embedded resource file

但没有什么事情发生。这些记录将不被处理(我知道,因为每一条记录被proccessed时,被标记在数据库中)。没有发生错误,但触发器不会触发,并且不执行作业。此外,CPU使用率按钮点击运行达50%以上,除非你去到IIS,停止和重新启动应用程序池犯规下去。这款CPU消耗不发生本地

But nothing else happens. The records are not processed (I know since every time a record is proccessed, is marked in the database). No errors occur, but the trigger is not fired, and the job is not executed. Also, the CPU usage run up to 50% or more on button click, and doesnt gets down unless you go to IIS, stop and restart the application pool. This cpu consumption doesn't happen locally.

修改,用调度为,由LeftyX建议,但仍获得远程服务器上相同的行为。

Changed use of scheduler for a singleton, as suggested by LeftyX, but still get same behavior on remote server.

我也试着使用 ADOJobStore (而不是 RAMJobStore 的我用它)。
现在,它仍然运转完好本地;但仍然不执行触发器(因此工作)在线。唯一的区别是,在线CPU使用率不运行达50%。
现在我可以看到,作业并触发创建(我查询表,看到这些记录存在),,但从来没有被执行

I also tried to use ADOJobStore (instead of RAMJobStore which I was using). Now it still works perfectly locally; but still doesn't execute the trigger (hence job) online. The only difference is that online the CPU usage doesn't run up to 50%. And now I can see that the job and trigger are created (I query the tables and see that those records exists), but never gets executed.

推荐答案

这是我注意到的一件事是在你的asp.net应用程序使用计划的< BR>
您应该使用单一对象。

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

process.aspx.cs 此行

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

创建了一个新的调度,但你应该用你静态的的Application_Start 创建的。

如果你想获得访问单实例使用公共memeber你的的Global.asax.cs

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;

,您可以在引用它的 process.aspx.cs

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

另一种解决方案是使用依赖注入。你可以在这里找到一些信息 使用的 StructureMap 这里 统一

更新:

您可以下载一个名为 AspNet_Quartz <一个示例应用程序(asp.net 4.0) href=\"https://skydrive.live.com/embed?cid=669ADF1AF64DF389&resid=669ADF1AF64DF389%21240&authkey=ALkHg5QqEypebro\"相对=nofollow>此处,看看它是如何工作的这里

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

这篇关于Quartz.net调度不火的工作/触发器一旦部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆