Skip to content

Commit

Permalink
fixed offline & Invalid date issue
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Jun 19, 2024
1 parent 7ad8c57 commit 7f7124c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions fedn/network/combiner/combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fedn/network/storage/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7f7124c

Please sign in to comment.