/// <summary> /// 更新节点状态 /// </summary> /// <param name="isStarted"></param> /// <param name="isOnStop"></param> private async Task MarkNodeAsync(bool isStarted, bool isOnStop = false) { using var _quartzDao = new QuartzDao(); bool isCreate = false; bool isSave = false; var node = await _quartzDao.QueryJobNodeByIdAsync(CoreGlobal.NodeSetting.NodeName); if (isStarted) { if (node == null) { isCreate = true; node = new JobNodesEntity(); node.GenerID = (await _quartzDao.QueryJobNodeMaxGId()) + 1; } node.NodeName = CoreGlobal.NodeSetting.NodeName; node.NodeType = CoreGlobal.NodeSetting.NodeType; node.MachineName = Environment.MachineName; node.AccessProtocol = CoreGlobal.NodeSetting.Protocol; node.Host = $"{CoreGlobal.NodeSetting.IP}:{CoreGlobal.NodeSetting.Port}"; node.Priority = CoreGlobal.NodeSetting.Priority; node.Status = NodeStatus.Run; node.AccessSecret = Guid.NewGuid().ToString("n"); node.LastUpdateTime = DateTime.Now; isSave = await _quartzDao.UpdateJobNodeStatusAsync(node) > 0; if (isCreate) { await _quartzDao.AddJobNodeAsync(node); } } else { if (node != null) { node.Status = isOnStop ? NodeStatus.Down : NodeStatus.Off; isSave = await _quartzDao.UpdateJobNodeStatusAsync(node) > 0; if (isOnStop) { node.AccessSecret = null; } } } if (isSave) { AccessSecret = node.AccessSecret; } CoreGlobal.NodeSetting.AccessSecret = AccessSecret; CoreGlobal.Generator = new Generator((short)node.GenerID, DateTime.Today); }
public Task <int> UpdateJobNodeStatusAsync(JobNodesEntity node) { return(_context.ExecuteAsync("UPDATE JobNodes SET NodeName=@NodeName,NodeType=@NodeType,MachineName=@MachineName,AccessProtocol=@AccessProtocol,Host=@Host,AccessSecret=@AccessSecret,LastUpdateTime=@LastUpdateTime,Status=@Status,Priority=@Priority WHERE NodeName=@NodeName", node)); }
public async Task <bool> AddJobNodeAsync(JobNodesEntity node) { return(await _context.ExecuteAsync("INSERT INTO JobNodes (NodeName,NodeType,MachineName,AccessProtocol,Host,AccessSecret,LastUpdateTime,Status,Priority,GenerID)VALUES (@NodeName,@NodeType,@MachineName,@AccessProtocol,@Host,@AccessSecret,@LastUpdateTime,@Status,@Priority,@GenerID)", node) == 1); }