gpt4 book ai didi

c# - Azure - 多个辅助角色 - 无法存储作业 : Unable to store Job: 'job6' ,,因为已存在具有此标识的作业

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:33 25 4
gpt4 key购买 nike

我正在使用 Quartz.Net 调度程序来安排我的作业。我正在使用 ADOJOBSTORE 来存储所有这些值。

无法存储作业:无法存储作业:“job6”,因为已存在具有此标识的作业当我尝试运行它时抛出上述错误。有什么想法吗?

        ILog log = LogManager.GetLogger(typeof(CronTrigger));

log.Info("------- Initializing -------------------");

// First we must get a reference to a scheduler
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();

log.Info("------- Initialization Complete --------");

log.Info("------- Scheduling Jobs ----------------");

// jobs can be scheduled before sched.start() has been called



// job 6 will run every 30 seconds but only on Weekdays (Monday through Friday)
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job6", "group1")
.Build();

ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity("trigger6", "group1")
.WithCronSchedule("0,30 * * ? * MON-FRI")
.Build();

DateTimeOffset ft = sched.ScheduleJob(job, trigger);
log.Info(job.Key + " has been scheduled to run at: " + ft
+ " and repeat based on expression: "
+ trigger.CronExpressionString);


log.Info("------- Starting Scheduler ----------------");

// All of the jobs have been added to the scheduler, but none of the
// jobs
// will run until the scheduler has been started
sched.Start();

log.Info("------- Started Scheduler -----------------");

//log.Info("------- Waiting five minutes... ------------");
//try
//{
// // wait five minutes to show jobs
// Thread.Sleep(300 * 1000);
// // executing...
//}
//catch (ThreadInterruptedException)
//{
//}

//log.Info("------- Shutting Down ---------------------");

//sched.Shutdown(true);

//log.Info("------- Shutdown Complete -----------------");

SchedulerMetaData metaData = sched.GetMetaData();
log.Info(string.Format("Executed {0} jobs.", metaData.NumberOfJobsExecuted));

这是我的 app.config 设置

<add key="quartz.scheduler.instanceId" value="AUTO"/>
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/>

<add key="quartz.jobStore.misfireThreshold" value="60000"/>


<add key="quartz.jobStore.clustered" value="true"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.dataSource" value="myDS"/>

<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"/>
<!-- i have modifed for this post -->
<add key="quartz.dataSource.myDS.connectionString" value="Server=mydatabaseconnectionstring goes here;Trusted_Connection=False;Encrypt=True;"/>

<add key="quartz.dataSource.myDS.provider" value="SqlServer-20"/>
<add key="quartz.jobStore.useProperties" value="true"/>

我可以做这样的事情...在添加作业或触发器之前检查数据库中的记录,如果不存在则添加作业?这样做可以吗?

- 或者 - 实现 Azure 队列来安排我的作业是否更容易?谢谢!!

最佳答案

这是因为 ScheduleJob 每次都会尝试添加作业。您应该使用带有重载的 AddJob 来指定是否覆盖现有作业,或者仅添加作业一次(检查是否存在),然后在需要时添加新触发器。

使用 AdoJobStore 时,触发器和作业将在第二次运行时保留下来。在您的情况下,您可能已经运行过一次代码,因此该作业存在于持久作业存储中。有了 RamJobStore,自然会是另一回事。

关于c# - Azure - 多个辅助角色 - 无法存储作业 : Unable to store Job: 'job6' ,,因为已存在具有此标识的作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11163977/

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