JobStore Quartz不保存历史记录

时间:2016-07-20 13:30:07

标签: c# .net database jobs quartz.net

我是石英新手,每次运行时我都会尝试让石英坚持下去。

我已经根据Quartz数据库创建了QRTZ_表,并且我将石英连接到我的数据库,但是在运行作业后,它在QRTZ_表上没有任何保存。我应该手动保存吗?或者我错过了一些配置?这是我的代码:

编辑:在此处发现了一个例外:

scheduler.Start();

获取Null引用异常,不知道为什么

配置文件:

<quartz>
<add key="quartz.scheduler.instanceName" value="MyScheduler"/>
<add key="quartz.scheduler.instanceId" value="instance_one"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="Normal"/>

<add key="quartz.scheduler.idleWaitTime" value ="5000"/>
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.tablePrefix" value="QRTZ_"/>
<add key="quartz.jobStore.clustered" value="false"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>

<add key="quartz.jobStore.dataSource" value="localhost"/>
<add key="quartz.dataSource.MySqlServerFullVersion.connectionStringName" value="C3MContext"/>
<add key="quartz.dataSource.MySqlServerFullVersion.connectionString" value="User ID=****;Password=****;Initial Catalog=novo_canalcc;Data Source=localhost"/>
<add key="quartz.dataSource.MySqlServerFullVersion.provider" value="SqlServer-20"/>
<add key="quartz.dataSource.useProperties" value="false"/>

配置作业:

var config = (NameValueCollection)ConfigurationManager.GetSection("quartz");

            ISchedulerFactory sf = new StdSchedulerFactory(config);

            //ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler scheduler = sf.GetScheduler("MyScheduler");
            scheduler.Start();

            foreach (var job in Jobs)
            {
                Log.Info($"Start schedule Job: {job}");

                IJobDetail jobDetail = JobBuilder.Create(job.GetType()).StoreDurably().Build();

                ITrigger trigger = TriggerBuilder.Create()
                    .WithSimpleSchedule
                      (s =>
                         s.WithIntervalInMinutes(job.IntervalInMinutes)
                        .RepeatForever()
                      )
                    .Build();

                scheduler.ScheduleJob(jobDetail, trigger);

                Log.Info($"Job schedule started: {job}");
            }

这是我的工作测试课程:

public class Class1 : IC3MJob
{
    private static readonly ILog Log = LogManager.GetLogger(typeof(Class1));

    public Class1()
    {
    }

    public void Execute(IJobExecutionContext context)
    {
        Log.Trace($"=========== {GetType().Name} started on: ===>>: {DateTime.Now}");

        //Do something

        Log.Trace($"=========== {GetType().Name} executed/finished on: ===>>: {DateTime.Now}");
    }

    public int IntervalInMinutes => Convert.ToInt16(ConfigurationManager.AppSettings["job.poc"]);
}

我正在这样称呼这个工作:

    [Test]
    public void test()
    {
        JobSchedule.Jobs.Add(new Class1());
        JobSchedule.Start();
    }

有什么想法吗?

0 个答案:

没有答案