public object ServiceInit() { ILog log = ServiceUtils.GetLogger("quartz.job.log"); log.Info("------- Initializing ----------------------"); try { ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sched = sf.GetScheduler(); JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(true, true); processor.ProcessFileAndScheduleJobs(string.Format("{0}/Config/Job.xml", AppDomain.CurrentDomain.BaseDirectory), sched, true); sched.Start(); } catch (Exception ex) { log.Error(ex); } return null; }
public void Start() { _logger.Debug("启动 JobEngine...."); try { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "quartz_jobs.xml"); var sf = new StdSchedulerFactory(); var processor = new JobSchedulingDataProcessor(true, true); _scheduledJobs = sf.GetScheduler(); processor.ProcessFileAndScheduleJobs(path, _scheduledJobs, false); _scheduledJobs.Start(); _logger.Debug("启动 JobEngine 完成."); } catch (Exception ex) { _logger.Error(ex.Message); _logger.Error(ex.StackTrace); } }
/// <summary> /// Register jobs and triggers (within a transaction, if possible). /// </summary> protected virtual void RegisterJobsAndTriggers() { ITransactionStatus transactionStatus = null; if (transactionManager != null) { transactionStatus = transactionManager.GetTransaction(new DefaultTransactionDefinition()); } try { if (jobSchedulingDataLocations != null) { JobSchedulingDataProcessor dataProcessor = new JobSchedulingDataProcessor(true, true); for (int i = 0; i < this.jobSchedulingDataLocations.Length; i++) { dataProcessor.ProcessFileAndScheduleJobs( jobSchedulingDataLocations[i], GetScheduler(), overwriteExistingJobs); } } // Register JobDetails. if (jobDetails != null) { foreach (JobDetail jobDetail in jobDetails) { AddJobToScheduler(jobDetail); } } else { // Create empty list for easier checks when registering triggers. jobDetails = new LinkedList(); } // Register Calendars. if (calendars != null) { foreach (DictionaryEntry entry in calendars) { string calendarName = (string) entry.Key; ICalendar calendar = (ICalendar) entry.Value; GetScheduler().AddCalendar(calendarName, calendar, true, true); } } // Register Triggers. if (triggers != null) { foreach (Trigger trigger in triggers) { AddTriggerToScheduler(trigger); } } } catch (Exception ex) { if (transactionStatus != null) { try { transactionManager.Rollback(transactionStatus); } catch (TransactionException) { logger.Error("Job registration exception overridden by rollback exception", ex); throw; } } if (ex is SchedulerException) { throw; } throw new SchedulerException("Registration of jobs and triggers failed: " + ex.Message); } if (transactionStatus != null) { transactionManager.Commit(transactionStatus); } }
/// <summary> /// 启动调度引擎 /// </summary> private void StartScheduler() { logger.Info("调度引擎开始启动"); ISchedulerFactory schedFactory = new StdSchedulerFactory(); sched = schedFactory.GetScheduler(); //读取配置文件中配置的Job和Trigger信息到Scheduler中 JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(true, true); processor.ProcessFile(ServiceMainSettings.GetConfig().ScheduleConfig); processor.ScheduleJobs(new Hashtable(), sched, false); //装在调度Job信息 string[] jobGroupNames = sched.JobGroupNames; if (jobGroupNames == null || jobGroupNames.Length <= 0) { logger.Debug("没有调度Job信息被装载"); } //开始执行调度任务 sched.Start(); logger.Info("调度引擎启动成功"); }
private void ProcessFile(JobFile jobFile) { if ((jobFile == null) || (jobFile.FileFound == false)) { return; } JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(Validating, ValidatingSchema); try { processor.ProcessFileAndScheduleJobs( jobFile.FilePath, jobFile.FilePath, // systemId scheduler, OverwriteExistingJobs); } catch (Exception e) { Log.Error("Error scheduling jobs: " + e.Message, e); } }