MVC3网站内作业调度 [英] Job Scheduler inside of MVC3 Website

查看:107
本文介绍了MVC3网站内作业调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在找工作调度程序设置为我的MVC3网站的使用里面的一些指导。我一直在看Quartz.NET这一点,但我有麻烦找在线指导,尽可能的设置,以确保当网站是它的运行。

I'm looking for some guidance in getting a Job Scheduler setup for use INSIDE of my MVC3 website. I've been looking at Quartz.NET for this, but am having trouble finding guidance online as far as the setup to make sure it's running when the website is.

通过上面的信息考虑在内。我知道一对夫妇的缺点来设置IIS内部的作业调度程序的。我要找设置的工作是简单的清理工作,其中时间是相当不重要的,所以如果IIS穿过并回收该线程的网站真的只是不会是一个大问题。 IE浏览器。如果它运行,由于回收每天10次/重新启动该网站线程,因为线程没有入门那很好,以及(虽然不太可能)。

With the information above taken into consideration. I'm aware of a couple of the "drawbacks" to setting up a job scheduler inside of IIS. The jobs that I'm looking to setup are simple cleanup jobs where timing is rather unimportant so if IIS goes through and recycles the thread for the website it really just won't be a big deal. ie. If it runs 10 times a day due to recycling/restarting the website thread that would be fine/If it runs once a month because the thread isn't getting started that's fine as well (although quite unlikely).

我似乎记得在SO或问题,通过谷歌后的表现设置它里面的的Application_Start()的Global.asax ,但不能在任何地方现在发现这个信息。有没有人对如何实施类似的东西,任何建议我在说什么?

I seem to recall a question on SO or a post through Google that showed setting it up inside of the Application_Start() in Global.asax, but can't find this info anywhere now. Does anyone have any recommendation on how to implement something similar to what I'm talking about?

推荐答案

在一些更多的搜索,我发现<一个href=\"http://stackoverflow.com/questions/1356789/how-to-use-quartz-net-with-asp-net\">this对这样的问题谈实施Quartz.NET的的Global.asax 文件里。

After some more searching I found this question on SO that talks about implementing Quartz.NET inside of the global.asax file.

要实现它,我只是在新引用的的Quartz.dll (这个帖子的时间)下载包并用以下code ...

To implement it I simply referenced the Quartz.dll in the new (at the time of this post) download package and used the following code...

    protected void Application_Start()
    {
        /*
         * Include other Application_Start() code...
         */

        //Job Scheduling
        try {
            //Setup the new Scheduler
            var sf = new StdSchedulerFactory();
            var sched = sf.GetScheduler();
            sched.Start();

            //Setup the Job
            var jobDetail = new JobDetailImpl( "myJob", null, typeof( DocCleanup ) );

            //Create 1 week trigger that will go on forever
            var trigger = new SimpleTriggerImpl( "jobTrigger", SimpleTriggerImpl.RepeatIndefinitely, new TimeSpan( 168, 0, 0 ) );
            trigger.StartTimeUtc = DateTimeOffset.Now;

            //Add the job to the scheduler
            sched.ScheduleJob( jobDetail, trigger );
        } catch (Exception ex) { //Implement Exception code... }
    }

我不希望建立一个控制台应用程序/ SQL作业的/ etc这个特定需要。这主要是由于极端联合国可靠性,在我的问题提到,从可以接受。有了,如果你需要任何形式的担保,以当作业的运行,我怀疑你会想用这种方式来实现Quartz.NET说。

I had no desire to create a console application/sql job/etc for this particular need. This is mainly due to the extreme un-reliability that is acceptable from it as mentioned in my question. With that said if you need ANY sort of guarantee as to when a job will run I doubt you will want to implement Quartz.NET in this manner.

这篇关于MVC3网站内作业调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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