Beispiel #1
0
        /// <summary>
        /// 启用任务调度
        /// 启动调度时会把任务表中状态为“执行中”的任务加入到任务调度队列中
        /// </summary>
        public static void StartScheduler()
        {
            try
            {
                if (!scheduler.IsStarted)
                {
                    //添加全局监听
                    scheduler.ListenerManager.AddTriggerListener(new CustomTriggerListener(), GroupMatcher <TriggerKey> .AnyGroup());
                    scheduler.Start();

                    ///获取所有执行中的任务
                    List <TaskModel> listTask = TaskActionHelper.GetAllTaskList().ToList <TaskModel>();

                    if (listTask != null && listTask.Count > 0)
                    {
                        foreach (TaskModel taskUtil in listTask)
                        {
                            try
                            {
                                ScheduleJob(taskUtil);
                            }
                            catch (Exception e)
                            {
                                LogHelper.LogHelper.CreateInstance.Error(string.Format("任务“{0}”启动失败!", taskUtil.TaskName), e);
                            }
                        }
                    }
                    LogHelper.LogHelper.CreateInstance.Info("任务调度启动成功!");
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogHelper.CreateInstance.Error("任务调度启动失败!", ex);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Job完成时调用
 /// </summary>
 /// <param name="trigger">触发器</param>
 /// <param name="context">上下文</param>
 /// <param name="triggerInstructionCode"></param>
 public void TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode)
 {
     TaskActionHelper.UpdateNextFireTime(trigger.JobKey.Name, TimeZoneInfo.ConvertTimeFromUtc(context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local));
 }
Beispiel #3
0
 /// <summary>
 ///  //Trigger触发后,job执行时调用本方法。true即否决,job后面不执行。
 /// </summary>
 /// <param name="trigger"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public bool VetoJobExecution(ITrigger trigger, IJobExecutionContext context)
 {
     TaskActionHelper.UpdateRecentRunTime(trigger.JobKey.Name, TimeZoneInfo.ConvertTimeFromUtc(context.FireTimeUtc.Value.DateTime, TimeZoneInfo.Local));
     return(false);
 }