Пример #1
0
        /// <summary>
        /// 恢复指定的作业
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public IBaseResponse ResumeTargetJob(J_JobInfo job)
        {
            IBaseResponse response = new BaseResponse() { Success = false };
            try
            {
                if (!sche.IsStarted) { sche.Start(); }

                sche.ResumeJob(new JobKey(job.JID.ToString(), job.JobGroup));
                response.Success = true;
                response.Message = string.Format("job:{0},group:{1}已恢复", job.JobName, job.JobGroup);
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = string.Format("job:{0},group:{1}恢复时出错", job.JobName, job.JobGroup);

            }
            //var scheduler_temp = new SchedulerFactory().GetScheduler();
            return response;
        }
Пример #2
0
        /// <summary>
        /// 删除某个作业
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public IBaseResponse RemovceJob(J_JobInfo job)
        {
            IBaseResponse response = new BaseResponse() { Success = false };
            try
            {
                var trigger = new TriggerKey(job.JID.ToString(), job.JobGroup);
                sche.PauseJob(new JobKey(job.JID.ToString(), job.JobGroup));
                sche.UnscheduleJob(trigger);
                sche.DeleteJob(new JobKey(job.JID.ToString(), job.JobGroup));
                response.Success = true;
                response.Message = string.Format("job:{0},group{1}已删除工作", job.JobName, job.JobGroup);
            }
            catch (Exception)
            {
                response.Message = string.Format("job:{0},group{1}删除工作时出错", job.JobName, job.JobGroup);
            }

            return response;
        }
Пример #3
0
        /// <summary>
        /// 终止指定作业
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public IBaseResponse RemoveJob(J_JobInfo job)
        {
            IBaseResponse response = new BaseResponse() { Success = false };
            try
            {

                sche.PauseJob(new JobKey(job.JID.ToString(), job.JobGroup));
                //1 取出指定的触发器
                var trigger = new TriggerKey(job.JID.ToString(), job.JobGroup);
                //2 先暂停触发器(试一下若不暂停触发器可否?——11月20日)
                sche.PauseTrigger(trigger);
                //3 调度中的该方法只能传入触发器
                sche.UnscheduleJob(trigger);

                response.Success = true;
                response.Message = string.Format("job:{0},group{1}已终止工作", job.JobName, job.JobGroup);
            }
            catch (Exception)
            {
                response.Message = string.Format("job:{0},group{1}终止工作时出错", job.JobName, job.JobGroup);
            }

            return response;
        }
Пример #4
0
        /// <summary>
        /// 暂停某个作业
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public IBaseResponse PauseJob(J_JobInfo job)
        {
            IBaseResponse response = new BaseResponse() { Success = false };

            try
            {
                sche.PauseJob(new JobKey(job.JID.ToString(), job.JobGroup));
                LogHelper.WriteLog(string.Format("{0}已恢复作业{1}-{2}(所属{3})", job.CreateUser, job.JID, job.JobName, job.JobGroup));
                response.Success = true;
                response.Message = string.Format("job:{0},group{1}已暂停工作", job.JobName, job.JobGroup);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("作业恢复错误", ex);

                response.Message = string.Format("job:{0},group{1}暂停工作时出错", job.JobName, job.JobGroup);
            }

            return response;
        }
Пример #5
0
        /// <summary>
        /// 根据工作对象 添加任务计划
        /// 作业需要含UID
        /// </summary>
        /// <param name="jobInfo">作业(含UID)</param>
        /// <param name="data_temp">向作业调度中传的临时数据</param>
        /// <returns></returns>
        public IBaseResponse AddScheduleJob(J_JobInfo jobInfo,IJobData data_temp)
        {
            //1 根据Job的类名通过反射的方式创建IJobDetial
            var job = JobFactory.CreateJobInstance(jobInfo, data_temp);
            IBaseResponse response = new BaseResponse() { Success = false };
            if (job == null)
            {
                response.Message = string.Format("创建作业实例时出错");
            }
            //2 创建定时器
            var trigger = JobFactory.CreateTrigger(jobInfo);

            //3 将定时器加入job中
            //var sche = new SchedulerFactory().GetScheduler();
            sche.ScheduleJob(job, trigger);
            try
            {
                //4 启动工作
                sche.Start();
                LogHelper.WriteLog(string.Format("{0}创建的作业{1}-{2}(所属{3})已添加至调度池中", jobInfo.CreateUser, jobInfo.JID, jobInfo.JobName, jobInfo.JobGroup));
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("作业添加错误",ex);
                throw;
            }

            response.Success = true;
            response.Message = string.Format("作业已添加至调度池中");
            return response;
        }
Пример #6
0
        /// <summary>
        /// 暂停某个作业
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public IBaseResponse PauseJob(J_JobInfo job)
        {
            IBaseResponse response = new BaseResponse() { Success = false };
            try
            {

                sche.PauseJob(new JobKey(job.JID.ToString(), job.JobGroup));
                response.Success = true;
                response.Message = string.Format("job:{0},group{1}已暂停工作", job.JobName, job.JobGroup);
            }
            catch (Exception ex)
            {
                response.Message = string.Format("job:{0},group{1}暂停工作时出错", job.JobName, job.JobGroup);
            }

            return response;
        }
Пример #7
0
        /// <summary>
        /// 根据工作对象 添加任务计划
        /// 作业需要含UID
        /// </summary>
        /// <param name="jobInfo">作业(含UID)</param>
        /// <param name="data_temp">向作业调度中传的临时数据</param>
        /// <returns></returns>
        public IBaseResponse AddScheduleJob(J_JobInfo jobInfo, PMS.Model.JobDataModel.SendJobDataModel data_temp)
        {
            //1 根据Job的类名通过反射的方式创建IJobDetial
            var job = JobFactory.CreateJobInstance(jobInfo, data_temp);
            IBaseResponse response = new BaseResponse() { Success = false };
            if (job == null)
            {
                response.Message = string.Format("创建作业实例时出错");
            }
            //2 创建定时器
            var trigger = JobFactory.CreateTrigger(jobInfo);

            //3 将定时器加入job中
            //var sche = new SchedulerFactory().GetScheduler();
            try
            {
                sche.ScheduleJob(job, trigger);
                //4 启动工作
                sche.Start();
                response.Success = true;
                response.Message = string.Format("作业已添加至调度池中");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = string.Format("作业添加至调度池时出错");
            }

            return response;
        }
Пример #8
0
 public IBaseResponse AddScheduleJob(J_JobInfo jobInfo, IJobData data_temp)
 {
     IBaseResponse response = new BaseResponse() { Success = false };
     return response;
 }