示例#1
0
        /// <summary>
        /// 直接使用 BookAppService.UpdateAsync 来更新实体
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            var jobInfoDto = await _jobInfoAppService.GetAsync(Id);

            ScheduleResult result = new ScheduleResult();

            if (jobInfoDto.JobStatus != JobInfo.JobStatus)
            {
                if (jobInfoDto.JobStatus == JobStatu.Deleted)
                {
                    //如果之前的状态是已删除的话,先创建任务再进行操作
                    await _scheduleCenter.AddJobAsync(JobInfo.JobName,
                                                      JobInfo.JobGroup,
                                                      JobInfo.JobNamespace + "." + JobInfo.JobClassName,
                                                      JobInfo.JobAssemblyName,
                                                      JobInfo.CronExpress,
                                                      JobInfo.StarTime,
                                                      JobInfo.EndTime);
                }
                if (JobInfo.JobStatus == JobStatu.Deleted)
                {
                    result = await _scheduleCenter.DeleteJobAsync(JobInfo.JobName, JobInfo.JobGroup);

                    if (result.Code == 0)
                    {
                        await _jobInfoAppService.DeleteAsync(Id);
                    }
                    return(NoContent());
                }
                else if (JobInfo.JobStatus == JobStatu.Running)
                {
                    result = await _scheduleCenter.ResumeJobAsync(JobInfo.JobName, JobInfo.JobGroup);
                }
                else
                {
                    result = await _scheduleCenter.StopJobAsync(JobInfo.JobName, JobInfo.JobGroup);
                }
            }
            if (result.Code == 0)
            {
                await _jobInfoAppService.UpdateAsync(Id, JobInfo);
            }
            return(NoContent());
        }
示例#2
0
        /// <summary>
        /// 直接使用 BookAppService.UpdateAsync 来更新实体
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            if (JobInfo.JobStatus == JobStatu.Deleted)
            {
                await _scheduleCenter.DeleteJobAsync(JobInfo.JobName, JobInfo.JobGroup);

                await _jobInfoAppService.DeleteAsync(Id);

                return(NoContent());
            }
            if (JobInfo.JobStatus == JobStatu.Running)
            {
                await _scheduleCenter.AddJobAsync(JobInfo);
            }
            else if (JobInfo.JobStatus == JobStatu.Stopped)
            {
                await _scheduleCenter.StopJobAsync(JobInfo.JobName, JobInfo.JobGroup);
            }
            await _jobInfoAppService.UpdateAsync(Id, JobInfo);

            return(NoContent());
        }