Beispiel #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            var executeLog = await ExecuteJob(context, async() => await Run(context));


            // 可以直接获取 JobDetail 的值
            var jobKey = context.JobDetail.Key;
            var jobId  = jobKey.Name;
            //var param = context.MergedJobDataMap;

            // 也可以通过数据库配置,获取传递过来的参数
            JobDataMap data = context.JobDetail.JobDataMap;
            //int jobId = data.GetInt("JobParam");

            var model = _tasksQzService.GetId(jobId);

            if (model != null)
            {
                model.RunTimes += 1;
                model.Remark    = LogHelpers.logWrite(executeLog);
                _tasksQzService.Update(model);
            }

            _logger.LogDebug(executeLog);
        }
Beispiel #2
0
        public IActionResult Update([FromBody] TasksUpdateDto parm)
        {
            //判断是否已经存在
            if (_tasksQzService.Any(m => m.Name == parm.Name && m.ID != parm.ID))
            {
                return(toResponse(StatusCodeType.Error, $"更新 {parm.Name} 失败,该用任务存在,不能重复!"));
            }

            // 根据 触发器模式 判断必填字段
            if (parm.TriggerType == 0)
            {
                if (parm.BeginTime == null || parm.EndTime == null)
                {
                    return(toResponse(StatusCodeType.Error, $"触发器 Simple 模式下,开始结束时间不能为空"));
                }

                if (parm.IntervalSecond <= 0)
                {
                    return(toResponse(StatusCodeType.Error, $"触发器 Simple 模式下,执行间隔时间不能小于 0 秒"));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(parm.Cron))
                {
                    return(toResponse(StatusCodeType.Error, $"触发器 Corn 模式下,运行时间表达式必须填写"));
                }
            }

            var tasksQz = _tasksQzService.GetFirst(m => m.ID == parm.ID);

            if (tasksQz.IsStart)
            {
                return(toResponse(StatusCodeType.Error, $"该任务正在运行中,请先停止在更新"));
            }

            var userSession = _tokenManager.GetSessionInfo();

            #region 更新任务信息

            var response = _tasksQzService.Update(m => m.ID == parm.ID, m => new Sys_TasksQz
            {
                Name           = parm.Name,
                JobGroup       = parm.JobGroup,
                Cron           = parm.Cron,
                AssemblyName   = parm.AssemblyName,
                ClassName      = parm.ClassName,
                Remark         = parm.Remark,
                BeginTime      = parm.BeginTime,
                EndTime        = parm.EndTime,
                TriggerType    = parm.TriggerType,
                IntervalSecond = parm.IntervalSecond,
                JobParams      = parm.JobParams,
                UpdateID       = userSession.UserID,
                UpdateName     = userSession.UserName,
                UpdateTime     = DateTime.Now
            });

            #endregion

            return(toResponse(response));
        }