示例#1
0
        public void RunBatchJobs()
        {
            lock (runBatchJobsLock)
            {
                log.Info("----------------------------------Invincible's dividing line---------------------------------------");
                log.Info("BatchJobs run start.");

                IList<Trigger> tobeFiredTriggerList = this.GetTobeFiredTrigger();

                if (tobeFiredTriggerList != null && tobeFiredTriggerList.Count > 0)
                {
                    //Parallel.ForEach(tobeFiredTriggerList, (tobeFiredTrigger) =>
                    foreach (Trigger tobeFiredTrigger in tobeFiredTriggerList)
                    {
                        Thread.Sleep(500);

                        JobDetail jobDetail = tobeFiredTrigger.JobDetail;
                        RunLog runLog = new RunLog();
                        try
                        {
                            #region Job运行前处理
                            BeforeJobRun(runLog, tobeFiredTrigger);
                            #endregion

                            #region Job参数获取
                            JobDataMap dataMap = new JobDataMap();
                            IList<JobParameter> jobParameterList = genericMgr.FindAllWithCustomQuery<JobParameter>
                                ("from JobParameter where JobCode = ?", jobDetail.Code);
                            if (jobParameterList != null && jobParameterList.Count > 0)
                            {
                                foreach (JobParameter jobParameter in jobParameterList)
                                {
                                    log.Debug("Set Job Parameter Name:" + jobParameter.Key + ", Value:" + jobParameter.Value);
                                    dataMap.PutData(jobParameter.Key, jobParameter.Value);
                                }
                            }
                            #endregion

                            #region Trigger参数获取
                            IList<TriggerParameter> triggerParameterList = genericMgr.FindAllWithCustomQuery<TriggerParameter>
                                ("from TriggerParameter where TriggerName = ?", tobeFiredTrigger.Name);
                            if (triggerParameterList != null && triggerParameterList.Count > 0)
                            {
                                foreach (TriggerParameter triggerParameter in triggerParameterList)
                                {
                                    log.Debug("Set Trigger Parameter Name:" + triggerParameter.Key + ", Value:" + triggerParameter.Value);
                                    if (!dataMap.ContainKey(triggerParameter.Key))
                                    {
                                        dataMap.PutData(triggerParameter.Key, triggerParameter.Value);
                                    }
                                }
                            }
                            #endregion

                            #region 运行Job
                            //反射方法
                            //object newInstance = Assembly.GetExecutingAssembly().CreateInstance("com.Sconit.Service.SI.Job", false);
                            //Type.GetType("com.Sconit.Service.SI.Job").GetMethod(jobDetail.ServiceType).Invoke(newInstance, new object[] { dataMap, container });
                            RunJob(jobDetail.ServiceType, dataMap);
                            genericMgr.FlushSession();
                            #endregion

                            #region Job运行后处理
                            AfterJobRunSuccess(runLog, tobeFiredTrigger);
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            AfterJobRunFail(runLog, tobeFiredTrigger, ex);
                        }
                        finally
                        {
                            #region 更新BatchTrigger
                            UpdateTrigger(tobeFiredTrigger);
                            #endregion
                        }
                    }
                    //);
                }
                else
                {
                    log.Info("No job found may run in this batch.");
                }

                log.Info("BatchJobs run end.");
            }
        }
示例#2
0
 private void AfterJobRunSuccess(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Job run successful. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description);
     genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ? where Id = ?",
         new object[] { DateTime.Now, CodeMaster.JobRunStatus.Success, runLog.Id });
     genericMgr.FlushSession();
 }
示例#3
0
 private void AfterJobRunFail(RunLog runLog, Trigger tobeFiredTrigger, Exception ex)
 {
     try
     {
         log.Error("Job run failure. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description, ex);
         if (ex.Message != null && ex.Message.Length > 1000)
         {
             genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ?, Message = ? where Id = ?",
                 new object[] { DateTime.Now, CodeMaster.JobRunStatus.Failure, ex.Message.Substring(0, 1000), runLog.Id });
         }
         else
         {
             genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ?, Message = ? where Id = ?",
                 new object[] { DateTime.Now, CodeMaster.JobRunStatus.Failure, ex.Message, runLog.Id });
         }
     }
     catch (Exception ex1)
     {
         log.Error(ex1.Message, ex1);
     }
 }
示例#4
0
 private void BeforeJobRun(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Start run job. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description);
     runLog.JobCode = tobeFiredTrigger.JobDetail.Code;
     runLog.TriggerName = tobeFiredTrigger.Name;
     runLog.StartTime = DateTime.Now;
     runLog.Status = CodeMaster.JobRunStatus.InProcess;
     genericMgr.Create(runLog);
     genericMgr.FlushSession();
 }