public ActionResult UpdateScheduling(UpdateSchedulingModel updateSchedulingModel) { if (updateSchedulingModel.Trigger != null) { updateSchedulingModel.TriggerIds.Add(updateSchedulingModel.Trigger.Value); } Data.Models.TaskScheduling scheduling = new Data.Models.TaskScheduling() { Id = updateSchedulingModel.Id, Name = updateSchedulingModel.Name, Description = updateSchedulingModel.Description, Api = updateSchedulingModel.Api, Status = SchedulingStateEnum.Stoped }; var list = taskTrigger.GetByIds(updateSchedulingModel.TriggerIds).Select(s => s.Crons); scheduling.NextRunTime = GetNextRunTimeByCrons(list); int count = taskScheduling.UpdateScheduling(scheduling, updateSchedulingModel.Id, updateSchedulingModel.TriggerIds); if (count > 0) { messageCenter.InsertTaskScheduling(Environment.MachineName, updateSchedulingModel.Id, 0, (int)SchedulingStateEnum.Stoped); return(new ResponseModel <string>(ErrorCode.success, "")); } return(new ResponseModel <string>(ErrorCode.server_exception, "")); }
public ActionResult AddScheduling(SchedulingModel schedulingModel) { if (taskScheduling.GetByName(schedulingModel.Name) != null) { return(new ResponseModel <string>(ErrorCode.record_exist, "")); } Data.Models.TaskScheduling scheduling = new Data.Models.TaskScheduling() { Name = schedulingModel.Name, Description = schedulingModel.Description, Api = schedulingModel.Api, Status = SchedulingStateEnum.Stoped }; if (schedulingModel.Trigger != null) { schedulingModel.TriggerIds.Add(schedulingModel.Trigger.Value); } List <DateTimeOffset> nextRunTimes = new List <DateTimeOffset>(); var list = taskTrigger.GetByIds(schedulingModel.TriggerIds).Select(s => s.Crons); scheduling.NextRunTime = GetNextRunTimeByCrons(list); //nextRunTimes[0].LocalDateTime; int count = taskScheduling.InsertScheduling(new List <object>() { scheduling, new { triggerIds = schedulingModel.TriggerIds } }); if (count > 0) { return(new ResponseModel <string>(ErrorCode.success, "")); } return(new ResponseModel <string>(ErrorCode.server_exception, "")); }
public ActionResult GetSchedulingList(string searchValue = "", int pageIndex = 1, int pageSize = 10) { Data.Models.TaskScheduling trigger = new Data.Models.TaskScheduling() { Description = searchValue, PageIndex = pageIndex, PageSize = pageSize }; var result = taskScheduling.GetPageList <Data.Models.TaskScheduling>(trigger); return(new ResponseModel <IEnumerable <Data.Models.TaskScheduling> >(ErrorCode.success, result, result.Count() > 0 ? result.First().Total : 0)); }
Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> > GetTriggersAndJobs(Data.Models.TaskScheduling scheduling) { IJobDetail jobDetail = JobBuilder.Create <SchedulingJob>() .WithIdentity("job-" + scheduling.Id) .UsingJobData("data", JsonSerializerHelper.Serialize(scheduling)) .Build(); //触发器 var triggers = taskTrigger.GetTaskTriggers(scheduling.Id); Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> > dictionary = new Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> >(); HashSet <ITrigger> triggerSet = new HashSet <ITrigger>(); foreach (var trigger in triggers) { if (trigger.Expire != null && trigger.Expire < DateTime.Now) { continue; } var tri = TriggerBuilder.Create().WithIdentity("trigger-" + scheduling.Id + "-" + trigger.Id); if (trigger.Activate == null) { tri.StartNow(); } else { DateTimeOffset?nextRunTime; if (trigger.Activate < DateTimeOffset.Now) { nextRunTime = new CronExpression(trigger.Crons).GetNextValidTimeAfter(DateTimeOffset.Now); } else { nextRunTime = trigger.Activate; } if (nextRunTime == null) { continue; } tri.StartAt(nextRunTime.Value); } tri.WithCronSchedule(trigger.Crons); if (trigger.Expire != null) { tri.EndAt(trigger.Expire); } triggerSet.Add(tri.Build()); } if (triggerSet.Count > 0) { dictionary.Add(jobDetail, triggerSet); } return(dictionary); }