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); }
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,
const std::string &Payload) {
std::lock_guard G(InfraMutex_);
@@ -84,15 +95,16 @@ namespace OpenWifi {
.toString(),
.LastUpdate = Utils::Now()};
auto s1 = MakeServiceListString(Services_);
Services_[PrivateEndPoint] = ServiceInfo;
if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) {
poco_information(
poco_information(
logger(),
fmt::format(
"Service {} ID={} is joining the system.",
"Service {} ID={} is joining the system. old={}",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
.toString(),
ID));
ID, s1));
std::string SvcList;
for (const auto &Svc : Services_) {
if (SvcList.empty())
@@ -135,13 +147,19 @@ namespace OpenWifi {
auto ServiceHint = Services_.begin();
auto now = Utils::Now();
auto si1 = Services_.size();
auto ss1 = MakeServiceListString(Services_);
while(ServiceHint!=Services_.end()) {
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);
} else
++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) {
logger().log(E);