stephb9959
2023-12-03 10:46:50 -08:00
parent 2b01453970
commit d2f70ec82d

View File

@@ -33,6 +33,17 @@ namespace OpenWifi {
void MicroService::Exit(int Reason) { std::exit(Reason); } void MicroService::Exit(int Reason) { std::exit(Reason); }
static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
std::string SvcList;
for (const auto &Svc : Services) {
if (SvcList.empty())
SvcList = Svc.second.Type;
else
SvcList += ", " + Svc.second.Type;
}
return SvcList;
}
void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key, void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key,
const std::string &Payload) { const std::string &Payload) {
std::lock_guard G(InfraMutex_); std::lock_guard G(InfraMutex_);
@@ -84,15 +95,16 @@ namespace OpenWifi {
.toString(), .toString(),
.LastUpdate = Utils::Now()}; .LastUpdate = Utils::Now()};
auto s1 = MakeServiceListString(Services_);
Services_[PrivateEndPoint] = ServiceInfo; Services_[PrivateEndPoint] = ServiceInfo;
if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) { if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) {
poco_information( poco_information(
logger(), logger(),
fmt::format( fmt::format(
"Service {} ID={} is joining the system.", "Service {} ID={} is joining the system. old={}",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE) Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
.toString(), .toString(),
ID)); ID, s1));
std::string SvcList; std::string SvcList;
for (const auto &Svc : Services_) { for (const auto &Svc : Services_) {
if (SvcList.empty()) if (SvcList.empty())
@@ -135,13 +147,19 @@ namespace OpenWifi {
auto ServiceHint = Services_.begin(); auto ServiceHint = Services_.begin();
auto now = Utils::Now(); auto now = Utils::Now();
auto si1 = Services_.size();
auto ss1 = MakeServiceListString(Services_);
while(ServiceHint!=Services_.end()) { while(ServiceHint!=Services_.end()) {
if ((now - ServiceHint->second.LastUpdate) > 120) { if ((now - ServiceHint->second.LastUpdate) > 120) {
poco_information(logger(), fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint)); poco_information(Logger_, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint));
ServiceHint = Services_.erase(ServiceHint); ServiceHint = Services_.erase(ServiceHint);
} else } else
++ServiceHint; ++ServiceHint;
} }
if(Services_.size() != si1) {
auto ss2 = MakeServiceListString(Services_);
poco_information(Logger_, fmt::format("Current list of microservices: {} -> {}", ss1, ss2));
}
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
logger().log(E); logger().log(E);