/// <summary> /// 执行 /// </summary> public override RunCommandResult Execute() { try { RefreshCommandQueueStatus refreshStatus = RefreshCommandQueueStatus.NoRefresh; if (CommandQueueScanManger.IsStopCommandQueue())//true 停止 { refreshStatus = RefreshCommandQueueStatus.Refreshing; } else { CommandQueueScanManger.StartScanCommandQueueAsync(); refreshStatus = RefreshCommandQueueStatus.Refreshing; } var r = NodeProxy.PostToServer <EmptyResponse, UpdateNodeRefreshCommandQueueStatusRequest>(ProxyUrl.UpdateNodeRefreshCmdQueueStatus_Url, new UpdateNodeRefreshCommandQueueStatusRequest() { NodeId = int.Parse(this.AppConfig["nodeid"]), Source = (Source)int.Parse(this.AppConfig["source"]), RefreshStatus = refreshStatus }); if (r.Status != ResponesStatus.Success) { ShowCommandLog("开启节点刷新命令队列失败,服务器返回:" + JsonConvert.SerializeObject(r)); } //添加日志 ShowCommandLog("开启节点刷新命令队列成功"); return(new RunCommandResult() { ExecuteStatus = ExecuteStatus.ExecuteSucess }); } catch (Exception ex) { ShowCommandLog("开启节点刷新命令队列异常,异常信息:" + JsonConvert.SerializeObject(ex)); return(new RunCommandResult() { ExecuteStatus = ExecuteStatus.ExecuteException, Ex = ex, Message = ex.Message }); } }
public void Start() { //OnInit("\r\n"); // OnInit("\r\n"); OnInit("----------------------" + DateTime.Now + ":初始化节点开始-----------------------------------------"); try { OnInit("**开始请求节点配置信息**"); if (System.Configuration.ConfigurationSettings.AppSettings.AllKeys.Contains("NodeID")) { GlobalNodeConfig.NodeID = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["NodeID"]); } var r = NodeProxy.PostToServer <LoadNodeConfigResponse, LoadNodeConfigRequest>(ProxyUrl.LoadNodeConfig_Url, new LoadNodeConfigRequest() { NodeId = GlobalNodeConfig.NodeID.ToString(), Source = Source.Node }); if (r.Status != ResponesStatus.Success) { //记录日志,并抛出异常 LogProxy.AddNodeErrorLog("请求" + ProxyUrl.LoadNodeConfig_Url + "获取节点配置失败,服务端返回信息:" + JsonConvert.SerializeObject(r)); throw new Exception("请求" + ProxyUrl.LoadNodeConfig_Url + "获取节点配置失败,服务端返回信息:" + JsonConvert.SerializeObject(r)); } GlobalNodeConfig.NodeInfo = r.Data.Node; GlobalNodeConfig.Alarm = r.Data.AlarmPerson.ToString(); if (GlobalNodeConfig.NodeID <= 0) { GlobalNodeConfig.NodeID = r.Data.Node.id; } //初始化配置信息 OnInit("**请求节点配置信息完成,请求结果:" + JsonConvert.SerializeObject(r) + "**"); //初始化命令池 OnInit("**开启初始化节点命令池**"); ICommandPoolBuilder builder = new CommandPoolBuilder(); builder.OnInitEvent += builder_OnInitEvent; builder.BuildCommandPool(); OnInit("**初始化节点命令池完成:本地节点命令池数量:" + CommandPoolManager.CreateInstance().GetList().Count + "**"); OnInit("**开始初始化监控线程**"); //初始化监控信息 GlobalNodeConfig.Monitors.Add(new NodeHeartBeatMonitor()); //心跳 GlobalNodeConfig.Monitors.Add(new TaskPerformanceMonitor()); //任务性能监控 GlobalNodeConfig.Monitors.Add(new NodePerformanceMonitor()); //节点性能监控 GlobalNodeConfig.Monitors.Add(new NodeTaskSchedulingMonitor()); //节点调度中的任务监控 GlobalNodeConfig.Monitors.Add(new NodeListenComandQueueMonitor()); //节点监听命令队列监控 GlobalNodeConfig.Monitors.Add(new TimingGcCollectMonitor()); //开启定时收集GC OnInit("**监控线程已开启**"); OnInit("**开启循环监听命令队列线程**"); IOHelper.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalNodeConfig.TaskSharedDllsDir + @"\"); CommandQueueScanManger.StartScanCommandQueueAsync();//循环监听命令队列线程 OnInit("**循环监听命令队列线程已开启**"); //刷新节点运行状态 var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateNodeStatusRequest>(ProxyUrl.UpdateNodeStatus_Url, new UpdateNodeStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, NodeStatus = Model.enums.NodeStatus.Running }); if (r2.Status != ResponesStatus.Success) { string msg = "更新节点运行状态失败,请求地址:" + ProxyUrl.UpdateNodeStatus_Url + ",服务器返回参数:" + JsonConvert.SerializeObject(r2); OnInit(msg); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "更新节点(" + GlobalNodeConfig.NodeID.ToString() + ")的运行状态失败", msg + ",节点启动日志:" + strLog.ToString()); } else { OnInit("更新节点运行状态成功"); } OnInit("节点启动成功"); } catch (Exception ex) { string exmsg = "节点启动异常:" + JsonConvert.SerializeObject(ex); OnInit(exmsg); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")启动异常,请注意查看", exmsg + ",节点启动日志:" + strLog.ToString()); } finally { OnInit("----------------------" + DateTime.Now + ":初始化节点结束-----------------------------------------"); LogProxy.AddNodeLog(strLog.ToString(), LogType.NodeInitLog); //log.Info(strLog.ToString()); // EventLogHelper.Info(strLog.ToString()); strLog.Clear(); } }