Beispiel #1
0
 public JobContext(Trigger trigger, JobDetail jobDetail, JobDataMap jobDataMap, IWindsorContainer container)
 {
     this.trigger = trigger;
     this.jobDetail = jobDetail;
     this.jobDataMap = jobDataMap;
     this.container = container;
 }
Beispiel #2
0
        private void UpdateTrigger(Trigger tobeFiredTrigger)
        {
            try
            {
                tobeFiredTrigger.TimesTriggered++;
                tobeFiredTrigger.PreviousFireTime = tobeFiredTrigger.NextFireTime;
                if (tobeFiredTrigger.RepeatCount != 0 && tobeFiredTrigger.TimesTriggered >= tobeFiredTrigger.RepeatCount)
                {
                    //关闭Trigger
                    log.Debug("Close Trigger:" + tobeFiredTrigger.Name);
                    tobeFiredTrigger.Status = CodeMaster.TriggerStatus.Close;
                    tobeFiredTrigger.NextFireTime = null;
                }
                else
                {
                    //设置下次运行时间
                    log.Debug("Set Trigger Next Start Time, Add:" + tobeFiredTrigger.Interval.ToString() + " " + tobeFiredTrigger.IntervalType);
                    DateTime dateTimeNow = DateTime.Now;
                    if (!tobeFiredTrigger.NextFireTime.HasValue)
                    {
                        tobeFiredTrigger.NextFireTime = dateTimeNow;
                    }

                    while (tobeFiredTrigger.NextFireTime.Value <= dateTimeNow)
                    {
                        if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Year)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddYears(tobeFiredTrigger.Interval);
                        }
                        else if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Month)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddMonths(tobeFiredTrigger.Interval);
                        }
                        else if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Day)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddDays(tobeFiredTrigger.Interval);
                        }
                        else if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Hour)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddHours(tobeFiredTrigger.Interval);
                        }
                        else if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Minute)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddMinutes(tobeFiredTrigger.Interval);
                        }
                        else if (tobeFiredTrigger.IntervalType == CodeMaster.TimeUnit.Second)
                        {
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddSeconds(tobeFiredTrigger.Interval);
                        }
                        else
                        {
                            throw new ArgumentException("invalid Interval Type:" + tobeFiredTrigger.IntervalType);
                        }
                    }
                    log.Debug("Trigger Next Start Time is set as:" + tobeFiredTrigger.NextFireTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                this.dao.ExecuteUpdateWithCustomQuery("update from Trigger set TimesTriggered = ?, PreviousFireTime = ?, NextFireTime = ?, Status = ? where Id = ?",
                        new object[] { tobeFiredTrigger.TimesTriggered, tobeFiredTrigger.PreviousFireTime, tobeFiredTrigger.NextFireTime, tobeFiredTrigger.Status, tobeFiredTrigger.Id });
            }
            catch (Exception ex)
            {
                log.Error("Error occur when update batch trigger.", ex);
            }
        }        
Beispiel #3
0
 private void AfterJobRunSuccess(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Job run successful. JobId:" + tobeFiredTrigger.JobDetail.Id + ", JobName:" + tobeFiredTrigger.JobDetail.Name);
     this.dao.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ? where Id = ?",
         new object[] { DateTime.Now, CodeMaster.JobRunStatus.Success, runLog.Id });
     this.dao.FlushSession();
 }
Beispiel #4
0
 private void AfterJobRunFail(RunLog runLog, Trigger tobeFiredTrigger, Exception ex)
 {
     try
     {
         log.Error("Job run failure. JobId:" + tobeFiredTrigger.JobDetail.Id + ", JobName:" + tobeFiredTrigger.JobDetail.Name, ex);
         if (ex.Message != null && ex.Message.Length > 255)
         {
             this.dao.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ?, Message = ? where Id = ?",
                 new object[] { DateTime.Now, CodeMaster.JobRunStatus.Failure, ex.Message.Substring(0, 255), runLog.Id });
         }
         else
         {
             this.dao.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);
     }
 }
Beispiel #5
0
 private void BeforeJobRun(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Start run job. JobId:" + tobeFiredTrigger.JobDetail.Id + ", JobName:" + tobeFiredTrigger.JobDetail.Name);
     runLog.JobDetailId = tobeFiredTrigger.JobDetail.Id;
     runLog.TriggerId = tobeFiredTrigger.Id;
     runLog.StartTime = DateTime.Now;
     runLog.Status = CodeMaster.JobRunStatus.InProcess;
     this.dao.Create(runLog);
     this.dao.FlushSession();
 }