Beispiel #1
0
        public async Task <ActionResult <BaseResponse> > ModifyJob(SchedulerJobRequest request)
        {
            if (!ValidateJob(request))
            {
                return(BaseResponse.GetResponse("Job参数错误"));
            }

            if (string.IsNullOrWhiteSpace(request.Id))
            {
                var job = Utils.MapperPropertyValue <SchedulerJobRequest, JobEntity>(request);
                job.Id = ObjectId.Default().NextString();
                var result = _jobStore.AddJob(job);
                if (result)
                {
                    if (request.RunNow)
                    {
                        var status = await StartJob(job);

                        return(BaseResponse.GetResponse(status.Success, $"任务创建成功! 状态:{status.Message}"));
                    }
                    return(BaseResponse.GetResponse(true, "任务创建成功"));
                }
                return(BaseResponse.GetResponse("任务创建失败"));
            }
            else
            {
                var job = _jobStore.QueryJob(request.Id);
                if (job == null)
                {
                    return(BaseResponse.GetResponse("任务不存在"));
                }
                if (job.Status != (int)JobStatus.Stop)
                {
                    return(BaseResponse.GetResponse("任务在停止状态下才能编辑"));
                }

                job.Name             = request.Name;
                job.FilePath         = request.FilePath;
                job.Remark           = request.Remark;
                job.IsSimple         = request.IsSimple;
                job.CronExpression   = request.CronExpression;
                job.RepeatCount      = request.RepeatCount;
                job.IntervalSeconds  = request.IntervalSeconds;
                job.AssemblyName     = request.AssemblyName;
                job.ClassName        = request.ClassName;
                job.CustomParamsJson = request.CustomParamsJson;
                job.StartTime        = request.StartTime;
                job.EndTime          = request.EndTime;

                var result = _jobStore.UpdateJob(job);
                return(BaseResponse.GetResponse(result));
            }
        }