public void QuartzTest(int type) { JobKey jobKey = new JobKey("demo", "group1"); switch (type) { //添加任务 case 1: var trigger = TriggerBuilder.Create() .WithDescription("触发器描述") .WithIdentity("test") //.WithSchedule(CronScheduleBuilder.CronSchedule("0 0/30 * * * ? *").WithMisfireHandlingInstructionDoNothing()) .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionNextWithRemainingCount()) .Build(); QuartzUtil.Add(typeof(MyJob), jobKey, trigger); break; //暂停任务 case 2: QuartzUtil.Stop(jobKey); break; //恢复任务 case 3: QuartzUtil.Resume(jobKey); break; } }
public void QuartzTask(int type) { JobKey jobKey = new JobKey("workTicket", "work"); switch (type) { //添加任务 case 1: var trigger = TriggerBuilder.Create() .WithDescription("workTicket") .WithIdentity("admin") //.WithSchedule(CronScheduleBuilder.CronSchedule("0 0/30 * * * ? *").WithMisfireHandlingInstructionDoNothing()) .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionIgnoreMisfires()) .Build(); Jobs._hub = _hub; _ = QuartzUtil.Add(typeof(Jobs), jobKey, trigger); break; //暂停任务 case 2: _ = QuartzUtil.Stop(jobKey); break; //恢复任务 case 3: _ = QuartzUtil.Resume(jobKey); break; //删除任务 case 4: _ = QuartzUtil.Delete(jobKey); break; } }
public void QuartzTask(string type, string jobName, string jobGroup) { JobKey jobKey = new JobKey(jobName, jobGroup); switch (type) { //添加任务 case "add": //创建触发器(也叫时间策略) var trigger = TriggerBuilder.Create() .WithDescription("workTicket") .WithIdentity("admin") //.WithSchedule(CronScheduleBuilder.CronSchedule("0 0/30 * * * ? *").WithMisfireHandlingInstructionDoNothing()) // 间隔固定时间执行 //.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever().WithMisfireHandlingInstructionIgnoreMisfires()) // 只执行一次 .WithSimpleSchedule(x => x.WithIntervalInSeconds(1).WithRepeatCount(0).WithMisfireHandlingInstructionIgnoreMisfires()) .Build(); switch (jobName) { case "AutoOperWorkTicket": //实例化Jobs用到的对象(singalr) AutoOperWorkTicketJobs._hub = _hub; //实例化Jobs用到的对象JobService AutoOperWorkTicketJobs.jobService = new JobService(_configuration); _ = QuartzUtil.Add(typeof(AutoOperWorkTicketJobs), jobKey, trigger); break; case "AutoOperQrCode": //实例化Jobs用到的对象(singalr) AutoOperQrCodeJobs._hub = _hub; //实例化Jobs用到的对象JobService AutoOperQrCodeJobs.jobService = new JobService(_configuration); _ = QuartzUtil.Add(typeof(AutoOperQrCodeJobs), jobKey, trigger); break; case "AutoRemindToWork": //实例化Jobs用到的对象(singalr) AutoRemindToWorkJobs._hub = _hub; //实例化Jobs用到的对象JobService AutoRemindToWorkJobs.jobService = new JobService(_configuration); _ = QuartzUtil.Add(typeof(AutoRemindToWorkJobs), jobKey, trigger); break; } break; //暂停任务 case "stop": _ = QuartzUtil.Stop(jobKey); break; //恢复任务 case "resume": _ = QuartzUtil.Resume(jobKey); break; //删除任务 case "delete": _ = QuartzUtil.Delete(jobKey); break; } }