Quartz Scheduler 的多作业不是 运行
Multi Job with Quartz Scheduler not running
我已经在我的服务中安排了三份工作
public partial class Service : ServiceBase
{
private IScheduler scheduler;
private static log4net.ILog _logFile =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Service()
{
InitializeComponent();
}
protected override async void OnStart(string[] args)
{
_logFile.Info("Service OnStart");
var factory = new StdSchedulerFactory();
scheduler = await factory.GetScheduler();
await scheduler.Start();
var job = JobBuilder.Create<SearchJob>()
.WithIdentity("SearchJob", "group1")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("SearchJobtrigger", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.SearchCronExp)
.ForJob(job)
.Build();
var jobUpload = JobBuilder.Create<UploadJob>()
.WithIdentity("UploadJob", "group1")
.Build();
var triggerUpload = TriggerBuilder.Create()
.WithIdentity("TriggerUploadJob", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.UploadCronExp)
.ForJob(jobUpload)
.Build();
var jobAwaiter = JobBuilder.Create<AwaiterJob>()
.WithIdentity("AwaiterJob", "group1")
.Build();
var triggerAwaiterJob = TriggerBuilder.Create()
.WithIdentity("triggerAwaiterJob", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.AwaiterCronExp)
.ForJob(jobAwaiter)
.Build();
await scheduler.ScheduleJob(job, trigger);
await scheduler.ScheduleJob(jobUpload, triggerUpload);
await scheduler.ScheduleJob(jobAwaiter, triggerAwaiterJob);
_logFile.Info("End Service OnStart");
}
protected override async void OnStop()
{
_logFile.Info("Service OnStop");
await scheduler.Shutdown();
}
}
查看日志,我注意到只有第一个作业启动,其他两个作业从未启动,但日志中没有错误。
我在调试中测试了服务并且作业正确执行,同时安装在版本号中编译的服务,这三个服务在一次执行和另一次执行之间的 CronExp 分别为 1,10,30 分钟
错误是由于 CronExp 的值不正确
我已经在我的服务中安排了三份工作
public partial class Service : ServiceBase
{
private IScheduler scheduler;
private static log4net.ILog _logFile =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Service()
{
InitializeComponent();
}
protected override async void OnStart(string[] args)
{
_logFile.Info("Service OnStart");
var factory = new StdSchedulerFactory();
scheduler = await factory.GetScheduler();
await scheduler.Start();
var job = JobBuilder.Create<SearchJob>()
.WithIdentity("SearchJob", "group1")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("SearchJobtrigger", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.SearchCronExp)
.ForJob(job)
.Build();
var jobUpload = JobBuilder.Create<UploadJob>()
.WithIdentity("UploadJob", "group1")
.Build();
var triggerUpload = TriggerBuilder.Create()
.WithIdentity("TriggerUploadJob", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.UploadCronExp)
.ForJob(jobUpload)
.Build();
var jobAwaiter = JobBuilder.Create<AwaiterJob>()
.WithIdentity("AwaiterJob", "group1")
.Build();
var triggerAwaiterJob = TriggerBuilder.Create()
.WithIdentity("triggerAwaiterJob", "group1")
.StartNow()
.WithCronSchedule(Settings.Default.AwaiterCronExp)
.ForJob(jobAwaiter)
.Build();
await scheduler.ScheduleJob(job, trigger);
await scheduler.ScheduleJob(jobUpload, triggerUpload);
await scheduler.ScheduleJob(jobAwaiter, triggerAwaiterJob);
_logFile.Info("End Service OnStart");
}
protected override async void OnStop()
{
_logFile.Info("Service OnStop");
await scheduler.Shutdown();
}
}
查看日志,我注意到只有第一个作业启动,其他两个作业从未启动,但日志中没有错误。 我在调试中测试了服务并且作业正确执行,同时安装在版本号中编译的服务,这三个服务在一次执行和另一次执行之间的 CronExp 分别为 1,10,30 分钟
错误是由于 CronExp 的值不正确