繁体   English   中英

Quartz.NET 和 AdoJobStore

[英]Quartz.NET and AdoJobStore

我已经为 Quartz.NET 创建了数据库。 将其配置为以这种方式使用 AdoJobStore:

        properties["quartz.scheduler.instanceName"] = "TestScheduler";
        properties["quartz.scheduler.instanceId"] = "instance_one";
        properties["quartz.threadPool.type"] = 
                   "Quartz.Simpl.SimpleThreadPool, Quartz";
        properties["quartz.threadPool.threadCount"] = "5";
        properties["quartz.threadPool.threadPriority"] = "Normal";
        properties["quartz.jobStore.misfireThreshold"] = "60000";
        properties["quartz.jobStore.type"] = 
                   "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "Q";
        properties["quartz.jobStore.clustered"] = "true";
        // if running MS SQL Server we need this
        properties["quartz.jobStore.lockHandler.type"] = 
                   "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";

        properties["quartz.dataSource.default.connectionString"] = 
                   "Server=.;Database=Test;Trusted_Connection=True;";
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";
        ISchedulerFactory sf = new StdSchedulerFactory(properties);
        IScheduler sched = sf.GetScheduler();

我在 JOB_DETAILS 表中添加了一个作业,因此在 TRIGGERS 和 CRONTRIGGERS 表中添加了一个触发器,但我的作业不会执行。 我使用 SQL Server Profiler 检查,Quartz 执行的唯一查询是SELECT * FROM QSchedulerState 我正在使用sched.Start(); 它不在 JOB_DETAILS 表中查找。 我不知道出了什么问题。

任何想法?

谢谢。

您是否通过 sql 将您的工作直接添加到表格中? 如果是这样,请尝试通过代码使用 api 注册作业。 如果没有别的,您可以检查您添加的内容是否与 api 生成的数据匹配

我同意 NinjaNye 的观点。 您必须使用 API 提交您的作业,因为它需要在运行时绑定您的类的命名空间。 过程非常简单

// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeHourlyTrigger();
// start on the next even hour
trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate(DateTime.UtcNow);  
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger); 

如您所见,我们正在向 JobDetail 传递我们的工作类型: typeof(HelloJob) 这将被调度程序用于在执行期间绑定我们的作业。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM