Ejemplo n.º 1
0
        public void LogErr(IJobExecutionContext context, string err)
        {
            LogErrModel model = new LogErrModel();

            if (context.Trigger is ICronTrigger)
            {
                var cTrigger = (ICronTrigger)context.Trigger;
                model.CronExpression = cTrigger.CronExpressionString ?? "-";
            }
            else
            {
                model.CronExpression = "-";
            }
            model.ErrDateTime  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            model.JobName      = context.JobDetail.Key.Name;
            model.JobGroupName = context.JobDetail.Key.Group;
            model.JobType      = context.JobDetail.JobType.FullName;
            model.JobData      = JobUtils.GetJobDataString(context.JobDetail.JobDataMap);
            model.ErrMessage   = err;

            lock (LockHelper)
            {
                _queueErrInfo.Enqueue(model);
            }
        }
Ejemplo n.º 2
0
        public static List <JobViewModel> GetJobList()
        {
            List <JobViewModel> list = new List <JobViewModel>();

            try
            {
                string path = GetXmlFilePath();
                var    data = XmlUtil.DeserializeXml <QuartzXmlConfiguration20>(path);
                if (data == null)
                {
                    return(list);
                }
                if (data.schedule == null || data.schedule.Length == 0)
                {
                    return(list);
                }

                foreach (var sch in data.schedule)
                {
                    if (sch.job == null || sch.job.Length == 0)
                    {
                        continue;
                    }

                    foreach (var job in sch.job)
                    {
                        JobViewModel model = new JobViewModel();

                        model.JobName      = job.name;
                        model.JobGroupName = job.group;
                        model.JobType      = job.jobtype;
                        model.JobData      = JobUtils.GetJobDataString(job.jobdatamap);

                        if (sch.trigger != null)
                        {
                            var tr = sch.trigger.SingleOrDefault(p => p.Item.jobname == job.name && p.Item.jobgroup == job.group);
                            if (tr != null)
                            {
                                var cd = tr.Item as cronTriggerType;
                                if (cd != null)
                                {
                                    model.CronExpression = cd.cronexpression;
                                }

                                var state = JobUtils.GetTriggerState(tr.Item.name, tr.Item.group);
                                model.JobState = JobUtils.GetTriggerStateValue(state);
                            }
                        }
                        list.Add(model);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(list);
        }