Exemple #1
0
        public async Task <string> StartAsync(int[] Ids)
        {
            BooleanResult result = new BooleanResult();

            var list = await _service.GetListByIdsAsync(Ids);

            if (list?.Count > 0)
            {
                list.ForEach(async x =>
                {
                    await _scheduleCenter.AddJobAsync(x.Name, x.Group, x.ClassName, x.Assembly, x.Cron);
                });
                result = await _service.UpdateStatusByIdsAsync(Ids, (int)TaskInfoStatus.Running);
            }
            return(JsonHelper.ObjectToJSON(result));
        }
Exemple #2
0
 /// <summary>
 /// 并且在 OnPostAsync 方法中调用了服务的 CreateAsync 方法
 /// </summary>
 /// <returns></returns>
 public async Task <IActionResult> OnPostAsync()
 {
     if (await _scheduleCenter.AddJobAsync(JobInfo))
     {
         JobInfo.JobStatus = JobStatu.Running;
         await _jobInfoAppService.CreateAsync(JobInfo);
     }
     return(NoContent());
 }
        public async Task <IActionResult> Index()
        {
            _logger.Info("TaskInfoController.Index");
            var data = await _taskInfoService.GetListByJobStatuAsync((int)TaskInfoStatus.Stopped);

            ViewData["data"] = data;
            var x   = data[0];
            var res = await _scheduleCenter.AddJobAsync(x.Name, x.Group, x.ClassName, x.Assembly, x.Cron);

            var c = res.ToString();

            return(View());
        }
Exemple #4
0
        /// <summary>
        /// 并且在 OnPostAsync 方法中调用了服务的 CreateAsync 方法
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            var result = await _scheduleCenter.AddJobAsync(JobInfo.JobName,
                                                           JobInfo.JobGroup,
                                                           JobInfo.JobNamespace + "." + JobInfo.JobClassName,
                                                           JobInfo.JobAssemblyName,
                                                           JobInfo.CronExpress,
                                                           JobInfo.StarTime,
                                                           JobInfo.EndTime);

            if (result.Code == 0)
            {
                JobInfo.JobStatus = JobStatu.Running;
                await _jobInfoAppService.CreateAsync(JobInfo);
            }
            return(NoContent());
        }
        /// <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());
        }
Exemple #6
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());
        }