Quartz的工作根本没有解雇

时间:2016-05-31 11:50:13

标签: c# api quartz-scheduler

我的石英工作有一个奇怪的情况。根本没有被解雇。 这是global.asax

中的配置
protected void Application_Start()
    {
        ...
        ControllerBuilder.Current.SetControllerFactory(new PnAwebAppControllerFactory());
        BootStrapper.ConfigureDependencies();
        GlobalConfig.CustomizeConfig(GlobalConfiguration.Configuration);

        GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
        GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);

        ConfigureQuartzJobs();
    }

它在我的配置结束时,方法如下

public static void ConfigureQuartzJobs()
    {
        // construct a scheduler factory
        var schedFact = new StdSchedulerFactory();

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

        // Create job for emails in que for all companies
        var jobEmailsQued = JobBuilder.Create<EmailQueJob>().WithIdentity("EmailQueJob", "group1").Build();

        // Create trigger for jobEmailsQued
        var triggerJobEmailsQued =
            TriggerBuilder.Create()
                .WithIdentity("TriggerEmailQueJob", "group1")
                .WithSchedule(CronScheduleBuilder.CronSchedule("0 0/2 * * * ?"))
                .ForJob(jobEmailsQued)
                .Build();

        // Schedule jobEmailsQued
        sched.ScheduleJob(jobEmailsQued, triggerJobEmailsQued);
    }

我正在使用visual studio的API模板应用程序。我做错了什么?

TNX!

经过一些测试,我得到了输出屏幕

A first chance exception of type 'System.ArgumentException' occurred in Quartz.dll

对我而言,这很奇怪,因为我有像这样的工作执行

public class EmailQueJob : IJob
{
    private readonly IMailMessageService _mailMessageService;

    private readonly AppLog _appLog;

    public EmailQueJob(IMailMessageService mailMessageService, AppLog appLog)
    {
        _mailMessageService = mailMessageService;
        _appLog = appLog;
    }

    public void Execute(IJobExecutionContext context)
    {
        try
        {
            Console.WriteLine("Some name");
        }
        catch (Exception ex)
        {
//                _appLog.LogError(ex, string.Format("Quartz job: email que, FAILED to execute.<br/>Error message: {0}.", ex.Message));
            var je = new JobExecutionException(ex);
            je.RefireImmediately = true;  //do something with the exception
            _appLog.LogError(ex, string.Format("Quartz job: email que, FAILED to execute.<br/>Error message: {0}.", je));
            throw je;  //throw JobExecutionException

        }

    }
}

此时进行测试只能通过控制台消息进行测试。发送电子邮件的实际代码我已经测试过并且有效。

0 个答案:

没有答案