Пример #1
0
        public JsonResult ModifyJob()
        {
            try
            {
                int             jobId     = Convert.ToInt32(Request["jobId"]);
                string          jobName   = Request["jobName"];
                CustomJobDetail customJob = CustomJobDetailBLL.CreateInstance().Get(jobId, jobName);

                IScheduler scheduler = QuartzNetHelper.GetScheduler();
                var        jobKey    = JobKey.Create(customJob.JobName, customJob.JobGroup);
                if (scheduler.CheckExists(jobKey))
                {
                    scheduler.DeleteJob(jobKey);
                }

                IJobDetail job = JobBuilder.Create <CustomHttpJob>()
                                 .WithIdentity(customJob.JobName, customJob.JobGroup)
                                 .Build();
                ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                       .StartAt(customJob.StartDate)
                                       .EndAt(customJob.EndDate)
                                       .WithIdentity(customJob.JobName, customJob.JobGroup)
                                       .WithCronSchedule(customJob.CronExpression)
                                       .WithDescription(customJob.Description)
                                       .Build();
                scheduler.ScheduleJob(job, trigger);

                return(Json(new { Code = 1, Message = "执行成功!" }));
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteExcepetion(ex);
                return(Json(new { Code = 0, Message = "执行失败!" }));
            }
        }
Пример #2
0
        public JsonResult DeleteJob()
        {
            try
            {
                IScheduler scheduler = QuartzNetHelper.GetScheduler();
                if (!scheduler.IsStarted)
                {
                    scheduler.Start();
                }
                int             jobId     = Convert.ToInt32(Request["jobId"]);
                string          jobName   = Request["jobName"];
                CustomJobDetail customJob = CustomJobDetailBLL.CreateInstance().Get(jobId, jobName);
                scheduler.PauseTrigger(new TriggerKey(customJob.JobName, customJob.JobGroup));
                scheduler.UnscheduleJob(new TriggerKey(customJob.JobName, customJob.JobGroup));

                var jobKey = JobKey.Create(customJob.JobName, customJob.JobGroup);
                if (scheduler.CheckExists(jobKey))
                {
                    var result = scheduler.DeleteJob(jobKey);

                    if (result)
                    {
                        CustomJobDetailBLL.CreateInstance().Delete(customJob.JobId, customJob.JobName);
                    }

                    if (result)
                    {
                        return(Json(new { Code = 1, Message = "执行成功!" }));
                    }
                    else
                    {
                        return(Json(new { Code = 0, Message = "执行失败!" }));
                    }
                }
                return(Json(new { Code = 1, Message = "执行成功!" }));
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteExcepetion(ex);
                return(Json(new { Code = 0, Message = "执行失败!" }));
            }
        }