Example #1
0
        protected override void Run()
        {
            try
            {
                var res = NodeProxy.PostToServer <EmptyResponse, UpdateNodeMonitorRequest>(ProxyUrl.UpdateNodeMonitorRequest_Url, new UpdateNodeMonitorRequest()
                {
                    MonitorClassName = this.GetType().Name, MonitorStatus = (int)MonitorStatus.Monitoring, NodeId = GlobalNodeConfig.NodeID, Source = Source.Node
                });
                if (res.Status != ResponesStatus.Success)
                {
                    LogProxy.AddNodeErrorLog(this.GetType().Name + "监控组件上报监控信息失败,请求地址:" + ProxyUrl.UpdateNodeMonitorRequest_Url + ",返回结果:" + JsonConvert.SerializeObject(res));
                }

                LoadTaskIdListRequest req = new LoadTaskIdListRequest()
                {
                    Source = Source.Node, TaskScheduleStatus = (int)TaskScheduleStatus.Scheduling, NodeId = GlobalNodeConfig.NodeID
                };
                var        r = NodeProxy.PostToServer <LoadTaskIdListResponse, LoadTaskIdListRequest>(ProxyUrl.LoadTaskIdList_Url, req);
                List <int> taskschdulinglist = TaskPoolManager.CreateInstance().GetList().Select(x => x.TaskModel.id).ToList();
                if (r.Status != ResponesStatus.Success)
                {
                    //如果服务端没有调度中的,则把本地在调度中的上报状态
                    if (taskschdulinglist.Count > 0)
                    {
                        UploadLocalTask(taskschdulinglist);
                    }
                    return;
                }

                List <int> taskidnotserver = taskschdulinglist.Where(x => !(r.Data.TaskIdList.Contains(x))).ToList();
                r.Data.TaskIdList.ForEach(x =>
                {
                    var taskruntimeInfo = TaskPoolManager.CreateInstance().Get(x.ToString());
                    if (taskruntimeInfo == null)//如果等于空值则报警,说明该任务再
                    {
                        string title             = "节点(id):" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + "),任务id:(" + x + ")" + ",调度异常,请及时处理!";
                        StringBuilder strContent = new StringBuilder();
                        strContent.AppendLine("所在节点名称(编号):" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeID + ")<br/>");
                        strContent.AppendLine("任务编号:" + x + "<br/>");
                        strContent.AppendLine("服务端任务状态:调度中<br/>");
                        strContent.AppendLine("节点端任务状态:任务池中已不存在该任务,调度异常<br/>");
                        AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, title, strContent.ToString());
                        LogProxy.AddNodeErrorLog(strContent.ToString());
                    }
                });
                if (taskidnotserver.Count > 0)
                {
                    UploadLocalTask(taskidnotserver);
                }
            }
            catch (Exception ex)
            {
                LogProxy.AddNodeErrorLog("节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监控调度中任务异常:" + ex.Message + ",异常:" + JsonConvert.SerializeObject(ex));
                AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监控调度中任务异常", JsonConvert.SerializeObject(ex));
            }
        }
        public ResponseBase <LoadTaskIdListResponse> LoadTaskIdList(LoadTaskIdListRequest req)
        {
            List <int> taskidlist = taskrep.Find(x => x.taskschedulestatus == req.TaskScheduleStatus).Select(x => x.id).ToList();

            if (taskidlist.Count <= 0)
            {
                return(ResponseToClient <LoadTaskIdListResponse>(ResponesStatus.Failed, ""));
            }
            return(ResponseToClient <LoadTaskIdListResponse>(ResponesStatus.Success, "", new LoadTaskIdListResponse()
            {
                TaskIdList = taskidlist
            }));
        }