Example #1
0
 public void SubmitForm(CustomerJobInfoEntity entity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         job.ModifyJobCron(entity);//更改运行中CRON
         entity.Modify(keyValue);
         service.Update(entity);
     }
     else
     {
         entity.Create();
         if (!string.IsNullOrEmpty(entity.RequestUrl) && (string.IsNullOrEmpty(entity.WebApi) || entity.WebApi == " "))
         {
             if (!entity.RequestUrl.Contains("http"))
             {
                 entity.RequestUrl = "http://" + entity.RequestUrl;
             }
             var uri = new Uri(entity.RequestUrl);
             entity.WebApi = "http://" + uri.Authority + "/api/Service/GetToken";//自动填充token验证
         }
         entity.DLLName          = "Quartz.Net_JobBase.dll";
         entity.FullJobName      = "Quartz.Net_JobBase.JobBase";
         entity.TriggerState     = "-1";
         entity.JobGroupName     = Common.GuId(); //动态分配
         entity.TriggerGroupName = Common.GuId(); //动态分配
         service.Insert(entity);
     }
 }
Example #2
0
        /// <summary>
        /// 暂停任务
        /// </summary>
        /// <param name="jobInfo">任务信息</param>
        /// <returns></returns>
        public bool PauseJob(CustomerJobInfoEntity jobInfo)
        {
            var jobKey = _createJobKey(jobInfo.JobName, jobInfo.JobGroupName);

            _scheduler.PauseJob(jobKey);
            _log.Info("PauseJob: " + jobInfo.JobName + " URL: " + jobInfo.RequestUrl + "  executing at " + DateTime.Now.ToString("r"));
            return(true);
        }
Example #3
0
        private void ResumeById(string keyValue)
        {
            CustomerJobInfoEntity model = GetForm(keyValue);

            model.TriggerState = "0"; //状态改为运行
            job.ResumeJob(model);     //恢复job
            UpdateForm(model);
        }
Example #4
0
        private void PauseById(string keyValue)
        {
            CustomerJobInfoEntity model = GetForm(keyValue);

            model.TriggerState = "1"; //状态改为暂停
            job.PauseJob(model);      //暂停job
            UpdateForm(model);
        }
Example #5
0
        private void RunById(string keyValue)
        {
            CustomerJobInfoEntity model = GetForm(keyValue);

            job.RunJob(model);        //运行job
            model.TriggerState = "0"; //状态改为运行中
            UpdateForm(model);
        }
Example #6
0
        private void DelById(string keyValue)
        {
            CustomerJobInfoEntity model = GetForm(keyValue);

            model.Deleted      = true;
            model.TriggerState = "5"; //状态改为删除
            job.DeleteJob(model);     //删除任务
            UpdateForm(model);
        }
Example #7
0
 public ActionResult SubmitForm(CustomerJobInfoEntity jobInfoEntity, string keyValue)
 {
     if (custApp.CheckFiled(jobInfoEntity.JobName))
     {
         return(Error("名称已存在。"));
     }
     custApp.SubmitForm(jobInfoEntity, keyValue);
     return(Success("操作成功。"));
 }
Example #8
0
        /// <summary>
        /// 更改任务运行周期
        /// </summary>
        /// <param name="jobInfo">任务信息</param>
        /// <returns></returns>
        public bool ModifyJobCron(CustomerJobInfoEntity jobInfo)
        {
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.CronSchedule(jobInfo.Cron);
            var      triggerKey = _createTriggerKey(jobInfo.TriggerName, jobInfo.TriggerGroupName);
            ITrigger trigger    = TriggerBuilder.Create().StartNow()
                                  .WithIdentity(jobInfo.TriggerName, jobInfo.TriggerGroupName)
                                  .WithSchedule(scheduleBuilder.WithMisfireHandlingInstructionDoNothing())
                                  .Build();

            _scheduler.RescheduleJob(triggerKey, trigger);
            _log.Info("ModifyJobCron: " + jobInfo.JobName + " URL: " + jobInfo.RequestUrl + "  executing at " + DateTime.Now.ToString("r"));
            return(true);
        }
Example #9
0
        /// <summary>
        /// 运行任务
        /// </summary>
        /// <param name="jobInfo">任务信息</param>
        /// <returns></returns>
        public bool RunJob(CustomerJobInfoEntity jobInfo)
        {
            Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + $"bin/{jobInfo.DLLName}");
            var      type     = assembly.GetType(jobInfo.FullJobName);
            JobKey   jobKey   = _createJobKey(jobInfo.JobName, jobInfo.JobGroupName);

            if (!_scheduler.CheckExists(jobKey))
            {
                IJobDetail job = JobBuilder.Create(type)
                                 .WithIdentity(jobKey)
                                 .UsingJobData(_createJobDataMap("jobId", jobInfo.F_Id))
                                 .UsingJobData(_createJobDataMap("requestUrl", jobInfo.RequestUrl))//添加此任务请求地址附带到Context上下文中
                                 .UsingJobData(_createJobDataMap("webApi", jobInfo.WebApi))
                                 .Build();

                CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.CronSchedule(jobInfo.Cron);
                ITrigger            trigger         = TriggerBuilder.Create().StartNow()//StartAt(DateTime.SpecifyKind(jobInfo.JobStartTime, DateTimeKind.Local))
                                                      .WithIdentity(jobInfo.TriggerName, jobInfo.TriggerGroupName)
                                                      .ForJob(jobKey)
                                                      .WithSchedule(scheduleBuilder.WithMisfireHandlingInstructionDoNothing())
                                                      .Build();
                #region Quartz 任务miss之后三种操作

                /*
                 * withMisfireHandlingInstructionDoNothing
                 * ——不触发立即执行
                 * ——等待下次Cron触发频率到达时刻开始按照Cron频率依次执行
                 *
                 * withMisfireHandlingInstructionIgnoreMisfires
                 * ——以错过的第一个频率时间立刻开始执行
                 * ——重做错过的所有频率周期后
                 * ——当下一次触发频率发生时间大于当前时间后,再按照正常的Cron频率依次执行
                 *
                 * withMisfireHandlingInstructionFireAndProceed
                 * ——以当前时间为触发频率立刻触发一次执行
                 * ——然后按照Cron频率依次执行*/
                #endregion

                _scheduler.ScheduleJob(job, trigger);
                _log.Info("RunJob: " + jobInfo.JobName + " URL: " + jobInfo.RequestUrl + "  executing at " + DateTime.Now.ToString("r"));
            }
            return(true);
        }
Example #10
0
 public void UpdateForm(CustomerJobInfoEntity entity)
 {
     service.Update(entity);
 }
Example #11
0
 public void Delete(CustomerJobInfoEntity entity)
 {
     service.Delete(entity);
 }
Example #12
0
        private void DhysicallyDelById(string keyValue)
        {
            CustomerJobInfoEntity model = GetForm(keyValue);

            Delete(model);
        }