public async Task TestEchoAsync(string address) { var node = await _serverNodeService.GetAsync(address); try { FunctionUtil.TRY(() => { using (var resp = (node.Address + "/home/echo").AsHttp().Send()) { if (resp.StatusCode == System.Net.HttpStatusCode.OK && resp.GetResponseContent() == "ok") { node.LastEchoTime = DateTime.Now; node.Status = Data.Entity.NodeStatus.Online; var report = GetClientReport(node); if (report != null) { if (_serverNodeClientReports.ContainsKey(node.Address)) { _serverNodeClientReports[node.Address] = report; } else { _serverNodeClientReports.AddOrUpdate(node.Address, report, (k, r) => report); } } } else { node.Status = Data.Entity.NodeStatus.Offline; } _serverNodeService.UpdateAsync(node); } }, 5); } catch (Exception e) { _logger.LogInformation(e, "Try test node {0} echo , but fail .", node.Address); } }
public Task TestEchoAsync() { return(Task.Run(async() => { while (true) { var nodes = await _serverNodeService.GetAllNodesAsync(); nodes.ForEach(n => { try { FunctionUtil.TRY(() => { using (var resp = (n.Address + "/home/echo").AsHttp().Send()) { if (resp.StatusCode == System.Net.HttpStatusCode.OK && resp.GetResponseContent() == "ok") { n.LastEchoTime = DateTime.Now; n.Status = Data.Entity.NodeStatus.Online; var report = GetClientReport(n); if (report != null) { _serverNodeClientReports.AddOrUpdate(n.Address, report, (k, r) => report); } } else { n.Status = Data.Entity.NodeStatus.Offline; } _serverNodeService.UpdateAsync(n); } }, 5); } catch (Exception e) { _logger.LogInformation(e, "Try test node {0} echo , but fail .", n.Address); } }); await Task.Delay(5000 * 1); } })); }