gpt4 book ai didi

.net - Quartz.NET 和 AdoJobStore

转载 作者:行者123 更新时间:2023-12-02 01:19:57 28 4
gpt4 key购买 nike

我已经为 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 表中查找。我不知道出了什么问题。

有什么想法吗?

谢谢。

最佳答案

我同意 NinjaNye 的观点。您必须使用 API 提交作业,因为它需要在运行时绑定(bind)类的 namespace 。过程很simple :

// 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)。调度程序将使用它在执行期间绑定(bind)我们的作业。

关于.net - Quartz.NET 和 AdoJobStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244358/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com