我正在尝试根据配置设置(如
)为Quarz.net中的作业构建触发器 var keysArray = [1,2]
keysArray.ForEach(key =>
{
//schedule will be unique for a key
var schedule = AppConfig.Get($"CronJobs.{key}.TimeSheetAutoSubmit.Schedule.QuarzExpression") ?? "0 30 23 * * ?";
var timeZoneId = AppConfig.Get($"CronJobs.{key}.TimeSheetAutoSubmit.TimeZoneId") ?? "India Standard Time";
var trigger = TriggerBuilder.Create()
.ForJob(jobDetail)
.WithCronSchedule(schedule, x => x
.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById(timeZoneId)))
.WithIdentity($"TimeSheetAutoSubmitTrigger_{key}")
.WithDescription($"ConfigKey_{key}")
.StartNow()
.Build();
Scheduler.ScheduleJob(jobDetail, trigger);
});
工作正常但问题是触发器在我检查日志时多次触发
2017-03-16 12:04:12,247 [DefaultQuartzScheduler_Worker-1] INFO UnitedLex.Services.JobHandlers.timesheetautosubmit - job started
2017-03-16 12:04:13,510 [DefaultQuartzScheduler_Worker-2] INFO UnitedLex.Services.JobHandlers.timesheetautosubmit - job started
2017-03-16 12:04:13,710 [DefaultQuartzScheduler_Worker-2] INFO UnitedLex.Services.JobHandlers.timesheetautosubmit - job started
不知道我在这里做错了什么......
答案 0 :(得分:1)
我可能错了,但我认为这是正常的,因为你的工作构建器/调度程序在foreach中,它被触发的次数等于你的数组的长度。
答案 1 :(得分:0)
如果您希望作业不以并发模式运行,请在作业定义中使用此属性[DisallowConcurrentExecution]
。
这样,下一个作业触发器将等待当前正在运行的作业完成。