从Windows服务执行Quartz.NET工作 [英] Executing Quartz.NET jobs from a Windows Service

查看:1554
本文介绍了从Windows服务执行Quartz.NET工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 4 Web应用程序和运行quartz.net作为Windows服务,共同记录根据这些来源配置:

I got a ASP.NET MVC 4 web application and quartz.net running as a windows service and common logging configured according to these sources :

<一个href=\"http://geekswithblogs.net/TarunArora/archive/2012/11/16/install-quartz.net-as-a-windows-service-and-test-installation.aspx\" rel=\"nofollow\">http://geekswithblogs.net/TarunArora/archive/2012/11/16/install-quartz.net-as-a-windows-service-and-test-installation.aspx

<一个href=\"http://geekswithblogs.net/TarunArora/archive/2012/11/17/quartz.net-windows-service-configure-logging.aspx\" rel=\"nofollow\">http://geekswithblogs.net/TarunArora/archive/2012/11/17/quartz.net-windows-service-configure-logging.aspx

和与此code在Global.asax中的地方:

and with this code in Global.asax in place:

        var properties = new NameValueCollection();
        properties["quartz.scheduler.instanceName"] = "ServerScheduler";

        // set thread pool info
        properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
        properties["quartz.threadPool.threadCount"] = "5";
        properties["quartz.threadPool.threadPriority"] = "Normal";

        // set remoting expoter
        properties["quartz.scheduler.proxy"] = "true";
        properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
        // construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory(properties);

        // get a scheduler
        IScheduler sched = schedFact.GetScheduler();
        sched.Start();

        IJobDetail jobDetail = JobBuilder.Create<SimpleJob>()
            .WithIdentity("simpleJob", "simpleJobs")
            .RequestRecovery()
            .Build();

        ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("simpleTrigger", "simpleTriggers")
            .StartNow()
            .WithSimpleSchedule(x => x.WithRepeatCount(4).WithIntervalInSeconds(10))
            .Build();

        sched.ScheduleJob(jobDetail, trigger);

和任务:

    public class SimpleJob : IJob
    {
        public SimpleJob()
    { 

    }

    public void Execute(IJobExecutionContext context)
    {
        Debug.WriteLine("I Executed at " + DateTime.Now.ToString());
    }
}

现在如果我运行的应用程序日志产生这样的5倍。

and now if I run the app the log produces something like this 5 times

    19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG    Quartz.Core.QuartzSchedulerThread - Batch acquisition of 1 triggers
    19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG Quartz.Simpl.SimpleJobFactory - Producing instance of Job 'simpleJobs.simpleJob', class=Navigate.Quartz.Jobs.SimpleJob
    19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG Quartz.Core.QuartzSchedulerThread - Batch acquisition of 1 triggers
    19:35:23 [ServerScheduler_Worker-1] DEBUG Quartz.Core.JobRunShell - Calling Execute on job simpleJobs.simpleJob
    19:35:23 [ServerScheduler_Worker-1] DEBUG Quartz.Core.JobRunShell - Trigger instruction : NoInstruction

然后删除触发和进行,但不执行工作,没有行被写入调试输出

Then deletes the trigger and carries on, but no job is executed and no lines are written to debug output

如果我通过没有通过NameValueCollection中的StdSchedulerFactory运行内嵌在应用中,然而调度,

if I run the scheduler embedded in the app, however, by not passing the NameValueCollection to the StdSchedulerFactory

    ISchedulerFactory schedFact = new StdSchedulerFactory();

一切工作正常,我也得到了行输出5次每次10秒。

everything works fine and I get the lines outputted 5 times every 10 seconds

    I Executed at 28.05.2013. 19:47:48
    I Executed at 28.05.2013. 19:47:58
    I Executed at 28.05.2013. 19:48:08
    I Executed at 28.05.2013. 19:48:18
    I Executed at 28.05.2013. 19:48:28

我在想什么,为什么心不是实际执行code中的Windows服务,该服务作为本地系统运行,如果我将其更改为管理员帐户寿没什么变化。任何帮助将AP preciated。

What am I missing, why isnt the windows service actually executing the code, the service is running as Local System, nothing changes if I change it to administrator account tho. Any help will be appreciated.

克里斯

推荐答案

我认为,该服务可能实际上是执行code,但你看不到的输出。尝试改变的Debug.WriteLine(),使得输出被包括在石英使用其日志输出相同的日志使用Common.Logging。对于code例子中看到 HTTP://netcommon.sourceforge。净/文档/ 1.2.0 /参考/ HTML / logging.html

I think that the service may actually be executing the code but you are not seeing the output. Try changing the Debug.WriteLine() to use Common.Logging so that the output is included in the same log that Quartz is using for its log output. For code examples see http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html.

我也看了,我们正在使用我们的执行code,我看,我们不这样做.GetScheduler之后。开始()()。既然你是用石英运行服务工作,调度应该已经启动,你应该刚刚与()是从.GetScheduler返回调度工作。尝试从您的code删除。开始()。

I also looked at the code that we are using in our implementation, and I see that we are not doing a .Start() after .GetScheduler(). Since you are working with a service running Quartz, the scheduler should already be started, and you should just work with the scheduler that is returned from .GetScheduler(). Try removing the .Start() from your code.

这篇关于从Windows服务执行Quartz.NET工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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