From 7f7124c8dcc5dbe2694cbc296a5f05d53f0485a4 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 19 Jun 2024 14:48:10 +0200 Subject: [PATCH] fixed offline & Invalid date issue --- fedn/network/combiner/combiner.py | 10 +++++----- fedn/network/storage/statestore/mongostatestore.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fedn/network/combiner/combiner.py b/fedn/network/combiner/combiner.py index 6681da603..afd9e4d67 100644 --- a/fedn/network/combiner/combiner.py +++ b/fedn/network/combiner/combiner.py @@ -267,7 +267,7 @@ def __join_client(self, client): """ if client.client_id not in self.clients.keys(): # The status is set to offline by default, and will be updated once _list_active_clients is called. - self.clients[client.client_id] = {"lastseen": datetime.now(), "status": "offline"} + self.clients[client.client_id] = {"last_seen": datetime.now(), "status": "offline"} def _subscribe_client_to_queue(self, client, queue_name): """Subscribe a client to the queue. @@ -329,7 +329,7 @@ def _list_active_clients(self, channel): for client in self._list_subscribed_clients(channel): status = self.clients[client]["status"] now = datetime.now() - then = self.clients[client]["lastseen"] + then = self.clients[client]["last_seen"] if (now - then) < timedelta(seconds=10): clients["active_clients"].append(client) # If client has changed status, update statestore @@ -575,7 +575,7 @@ def SendHeartbeat(self, heartbeat: fedn.Heartbeat, context): # Update the clients dict with the last seen timestamp. client = heartbeat.sender self.__join_client(client) - self.clients[client.client_id]["lastseen"] = datetime.now() + self.clients[client.client_id]["last_seen"] = datetime.now() response = fedn.Response() response.sender.name = heartbeat.sender.name @@ -612,14 +612,14 @@ def TaskStream(self, response, context): # Set client status to online self.clients[client.client_id]["status"] = "online" - self.statestore.set_client({"name": client.name, "status": "online", "client_id": client.client_id}) + self.statestore.set_client({"name": client.name, "status": "online", "client_id": client.client_id, "last_seen": datetime.now()}) # Keep track of the time context has been active start_time = time.time() while context.is_active(): # Check if the context has been active for more than 10 seconds if time.time() - start_time > 10: - self.clients[client.client_id]["lastseen"] = datetime.now() + self.clients[client.client_id]["last_seen"] = datetime.now() # Reset the start time start_time = time.time() try: diff --git a/fedn/network/storage/statestore/mongostatestore.py b/fedn/network/storage/statestore/mongostatestore.py index 6bf3be4ff..71738d565 100644 --- a/fedn/network/storage/statestore/mongostatestore.py +++ b/fedn/network/storage/statestore/mongostatestore.py @@ -924,7 +924,7 @@ def update_client_status(self, clients, status): :return: None """ datetime_now = datetime.now() - filter_query = {"name": {"$in": clients}} + filter_query = {"client_id": {"$in": clients}} update_query = {"$set": {"last_seen": datetime_now, "status": status}} self.clients.update_many(filter_query, update_query)