public virtual void Execute(JobExecutionContext context) { Logger logger = LogManager.GetCurrentClassLogger(); string instName = context.JobDetail.Name; var jobs = context.Scheduler.GetCurrentlyExecutingJobs(); foreach (JobExecutionContext job in jobs) { if (job.Trigger == context.Trigger && !(job.JobInstance == this)) { logger.Debug("There's another instance running, so leaving" + this); return; } } logger.Debug("Start job: " + instName); //запустим обмен в отдельном экземпляре ServiceSA1C _serviceSA1C = new ServiceSA1C(); _serviceSA1C.ExecuteExchange(context.JobDetail.Name, false); }
public virtual void Execute(JobExecutionContext context) { Logger logger = LogManager.GetCurrentClassLogger(); string instName = context.JobDetail.Name; var jobs = context.Scheduler.GetCurrentlyExecutingJobs(); foreach (JobExecutionContext job in jobs) { if (job.Trigger == context.Trigger && !(job.JobInstance == this)) { logger.Debug("There's another instance running, so leaving" + this); return; } } //logger.Debug("Start job: "+instName); ServiceSA1C _serviceSA1C = new ServiceSA1C(); var baseConfig = from conf in _serviceSA1C.config.basesConfig select new { conf.Name, conf.JobSheduler.Expression, conf.JobSheduler.isEnable }; foreach (var c in baseConfig) { //logger.Debug("Set : "+c.Name); Trigger trigger = context.Scheduler.GetTrigger(c.Name, null); if (!c.isEnable && trigger != null) { //надо отключить logger.Debug("Delete job"); context.Scheduler.DeleteJob(c.Name, null); continue; } if ((c.isEnable && trigger == null)) { //нужно создать logger.Debug("Create new job"); JobDetail jobDetail = new JobDetail(c.Name, null, typeof(ExchangeJob)); trigger = new CronTrigger(c.Name, null, c.Expression); // со следующей секунды trigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow); //trigger.Name = "myTrigger"; context.Scheduler.ScheduleJob(jobDetail, trigger); continue; } if (trigger != null) { //Trigger newTrigger = new CronTrigger(c.Name,null,c.Expression); CronTrigger tg = (CronTrigger)(trigger); //int result = trigger.CompareTo(newTrigger); if (tg.CronExpressionString != c.Expression) { logger.Debug("Trigger change. Delete old and create new"); context.Scheduler.DeleteJob(c.Name, null); JobDetail jobDetail = new JobDetail(c.Name, null, typeof(ExchangeJob)); trigger = new CronTrigger(c.Name, null, c.Expression); trigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow); context.Scheduler.ScheduleJob(jobDetail, trigger); } } // со следующей секунды //trigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow); //trigger.Name = "myTrigger"; //sched.ScheduleJob(jobDetail, trigger); } }