Пример #1
0
        public async Task <Result <JobTaskStatus> > StartJobTask(long sid)
        {
            var result = new Result <JobTaskStatus> {
                Message = "启动任务成功!"
            };

            try
            {
                result = await StartWithRetry(sid);

                if (result.Success && result.Data != JobTaskStatus.Running)
                {
                    using var _quartzDao = new QuartzDao();
                    var isOk = await _quartzDao.UpdateJobTaskStatusAsync(sid, JobTaskStatus.Running);

                    result.Data = isOk ? JobTaskStatus.Running : result.Data;
                }
            }
            catch (Exception ex)
            {
                result.Success     = false;
                result.Message     = $"节点[{CoreGlobal.NodeSetting.NodeName}]任务调度平台启动任务失败!";
                result.ErrorDetail = ex.Message;
                _logger.LogError(ex, $"节点[{CoreGlobal.NodeSetting.NodeName}]任务调度平台启动任务失败!");
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        ///立即运行一次任务
        /// </summary>
        /// <param name="sid"></param>
        public async Task <Result <ResultStatus> > RunOnceTask(long sid)
        {
            var result = new Result <ResultStatus> {
                Data = ResultStatus.Success, Message = $"运行一次成功!"
            };

            try
            {
                using var _quartzDao = new QuartzDao();
                var task = await _quartzDao.QueryJobTaskAsync(sid);

                if (task == null)
                {
                    result.Data    = ResultStatus.Failed;
                    result.Success = false;
                    result.Message = "任务不存在!";
                    return(result);
                }
                if (task.Status != JobTaskStatus.Running)
                {
                    result.Data    = ResultStatus.Failed;
                    result.Success = false;
                    result.Message = "在运行状态下才能运行一次任务!";
                    return(result);
                }
                var ret = await RunOnce(sid);

                if (ret.Success)
                {
                    var isOk = await _quartzDao.UpdateJobTaskStatusAsync(sid, task.Status, count : 1);

                    result.Data    = isOk ? ResultStatus.Success : ResultStatus.Failed;
                    result.Message = $"运行一次任务{(isOk ? "成功" : "失败")}!";
                }
            }
            catch (Exception exp)
            {
                _logger.LogError(exp, $"节点[{CoreGlobal.NodeSetting.NodeName}][({sid})]运行一次任务失败!");
                result.Success     = false;
                result.Message     = $"运行一次任务失败";
                result.ErrorDetail = exp.Message;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 停止一个任务
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public async Task <Result <JobTaskStatus> > StopTask(long sid)
        {
            var result = new Result <JobTaskStatus>();

            try
            {
                using var _quartzDao = new QuartzDao();
                var task = await _quartzDao.QueryJobTaskAsync(sid);

                if (task == null)
                {
                    result.Success = false;
                    result.Message = $"任务不存在!";
                    return(result);
                }
                result.Data = task.Status;
                if (task.Status <= JobTaskStatus.Stop)
                {
                    result.Success = false;
                    result.Message = "大于停止状态下才能恢复运行!";
                    return(result);
                }

                var ret = await Stop(sid);

                if (ret.Success)
                {
                    var isOk = await _quartzDao.UpdateJobTaskStatusAsync(sid, JobTaskStatus.Stop, true);

                    result.Data    = isOk ? JobTaskStatus.Stop : result.Data;
                    result.Message = $"停止运行任务成功!任务状态:[{result.Data.GetDescription()}]";
                }
            }
            catch (Exception exp)
            {
                _logger.LogError(exp, $"节点[{CoreGlobal.NodeSetting.NodeName}][({sid})]停止运行任务失败!");
                result.Success     = false;
                result.Message     = $"停止运行任务失败!任务状态:[{result.Data.GetDescription()}]";
                result.ErrorDetail = exp.Message;
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 暂停一个任务
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public async Task <Result <JobTaskStatus> > PauseTask(long sid)
        {
            var result = new Result <JobTaskStatus>();

            try
            {
                using var _quartzDao = new QuartzDao();
                var task = await _quartzDao.QueryJobTaskAsync(sid);

                if (task == null)
                {
                    result.Success = false;
                    result.Message = $"任务不存在!";
                    return(result);
                }
                result.Data = task.Status;
                if (task.Status != JobTaskStatus.Running)
                {
                    result.Success = false;
                    result.Message = "在运行状态下才能暂停任务!";
                    return(result);
                }

                var ret = await Pause(sid);

                if (ret.Success)
                {
                    var isOk = await _quartzDao.UpdateJobTaskStatusAsync(sid, JobTaskStatus.Paused, true);

                    result.Data    = isOk ? JobTaskStatus.Paused : result.Data;
                    result.Message = $"暂停成功!任务状态:[{result.Data.GetDescription()}]";
                }
            }
            catch (Exception exp)
            {
                _logger.LogError(exp, $"节点[{CoreGlobal.NodeSetting.NodeName}][({sid})]任务暂停运行失败!");
                result.Success     = false;
                result.Message     = $"暂停失败!任务状态:[{result.Data.GetDescription()}]";
                result.ErrorDetail = exp.Message;
            }
            return(result);
        }