示例#1
0
        /// <summary>
        /// 获取task信息
        /// </summary>
        /// <returns></returns>
        public static List <ScheduleJobModel> GetAllTasks()
        {
            if (manager == null)
            {
                throw new Exception("请先开启服务");
            }
            //所有任务
            var jobKeys = manager.GetJobKeys(GroupMatcher <JobKey> .AnyGroup());
            //正在运行的任务
            var runningJobs = manager.GetCurrentlyExecutingJobs();

            var list = new List <ScheduleJobModel>();

            foreach (var jobKey in jobKeys)
            {
                var triggers = manager.GetTriggersOfJob(jobKey);
                if (!ValidateHelper.IsPlumpList(triggers))
                {
                    continue;
                }
                foreach (var trigger in triggers)
                {
                    var job = new ScheduleJobModel();

                    job.JobName  = jobKey.Name;
                    job.JobGroup = jobKey.Group;

                    job.TriggerName  = trigger.Key.Name;
                    job.TriggerGroup = trigger.Key.Group;

                    //trigger information
                    job.StartTime       = trigger.StartTimeUtc.DateTime;
                    job.PreTriggerTime  = trigger.GetPreviousFireTimeUtc()?.DateTime;
                    job.NextTriggerTime = trigger.GetNextFireTimeUtc()?.DateTime;
                    job.JobStatus       = GetTriggerState(manager.GetTriggerState(trigger.Key));

                    //判断是否在运行
                    job.IsRunning = runningJobs?.Any(x => x.JobDetail.Key == jobKey) ?? false;

                    list.Add(job);
                }
            }
            return(list);
        }
示例#2
0
        /// <summary>
        /// 获取task信息
        /// </summary>
        /// <returns></returns>
        public static List <ScheduleJobModel> GetAllTasks_(this IScheduler manager)
        {
            //所有任务
            var jobKeys = manager.GetAllJobKeys_();
            //正在运行的任务
            var runningJobs = manager.GetCurrentlyExecutingJobs();

            var list = new List <ScheduleJobModel>();

            foreach (var jobKey in jobKeys)
            {
                var triggers = manager.GetTriggersOfJob(jobKey);
                if (!ValidateHelper.IsPlumpList(triggers))
                {
                    continue;
                }
                foreach (var trigger in triggers)
                {
                    var job = new ScheduleJobModel();

                    job.JobName  = jobKey.Name;
                    job.JobGroup = jobKey.Group;

                    job.TriggerName  = trigger.Key.Name;
                    job.TriggerGroup = trigger.Key.Group;

                    //trigger information
                    job.StartTime       = trigger.StartTimeUtc.LocalDateTime;
                    job.PreTriggerTime  = trigger.GetPreviousFireTimeUtc()?.LocalDateTime;
                    job.NextTriggerTime = trigger.GetNextFireTimeUtc()?.LocalDateTime;
                    job.JobStatus       = manager.GetTriggerState(trigger.Key).GetTriggerState();

                    //判断是否在运行
                    job.IsRunning = runningJobs.Any(x => x.JobDetail.Key == jobKey);

                    list.Add(job);
                }
            }
            return(list);
        }