MCPcopy Create free account
hub / github.com/OpenArkStudio/ARK / HealthCheck

Method HealthCheck

src/plugin/net/src/AFCNetServiceManagerModule.cpp:51–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void AFCNetServiceManagerModule::HealthCheck(uint64_t timer_id, const AFGUID& entity_id)
52{
53 // check if I need to connect other servers from consul center.
54 std::vector<ARK_APP_TYPE> target_list;
55 m_pBusModule->GetTargetBusRelations(target_list);
56
57 if (target_list.empty())
58 {
59 return;
60 }
61
62 auto reg_center = m_pBusModule->GetRegCenter();
63 for (auto target : target_list)
64 {
65 const auto& name = m_pBusModule->GetAppName(target);
66 if (name.empty())
67 {
68 continue;
69 }
70
71 auto ret = m_pConsulModule->GetHealthServices(reg_center.service_name, name);
72 ret.Then([=](const std::pair<bool, std::string>& response) {
73 if (!response.first)
74 {
75 return;
76 }
77
78 using json = nlohmann::json;
79
80 json resp_json = json::parse(response.second);
81 if (!resp_json.is_array())
82 {
83 return;
84 }
85
86 for (json::iterator iter = resp_json.begin(); iter != resp_json.end(); ++iter)
87 {
88 auto& health_check_json = iter.value();
89 auto& service_json = health_check_json["Service"];
90 if (!service_json.is_object())
91 {
92 continue;
93 }
94
95 consul::service_data service_msg;
96 google::protobuf::util::JsonParseOptions option;
97 option.ignore_unknown_fields = true;
98 auto status = google::protobuf::util::JsonStringToMessage(service_json.dump(), &service_msg, option);
99 if (!status.ok())
100 {
101 continue;
102 }
103
104 auto find_iter = service_msg.meta().find("busid");
105 if (find_iter == service_msg.meta().end())
106 {
107 ARK_LOG_ERROR("service={} do not have Meta=busid, please check it.", service_msg.id());
108 return;

Callers

nothing calls this directly

Calls 12

parseFunction · 0.85
GetTargetBusRelationsMethod · 0.80
GetHealthServicesMethod · 0.80
ThenMethod · 0.80
dumpMethod · 0.80
okMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
valueMethod · 0.45
findMethod · 0.45
FromStringMethod · 0.45

Tested by

no test coverage detected