Skip to content

Commit

Permalink
bugfix/SK-850 | Sets client status to online in database when client …
Browse files Browse the repository at this point in the history
…connects (#606)

* Sets client status to online in database when client connects. Also clean up status of previously connected clients on startup.
  • Loading branch information
stefanhellander authored May 16, 2024
1 parent 0b83d6b commit 368850b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fedn/network/combiner/combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def __init__(self, config):
# Client queues
self.clients = {}

self.modelservice = ModelService()

# Validate combiner name
match = re.search(VALID_NAME_REGEX, config["name"])
Expand Down Expand Up @@ -122,6 +121,17 @@ def __init__(self, config):
self.repository = Repository(announce_config["storage"]["storage_config"])

self.statestore = MongoStateStore(announce_config["statestore"]["network_id"], announce_config["statestore"]["mongo_config"])

# Fetch all clients previously connected to the combiner
# If a client and a combiner goes down at the same time,
# the client will be stuck listed as "online" in the statestore.
# Set the status to offline for previous clients.
previous_clients = self.statestore.clients.find({"combiner": config["name"]})
for client in previous_clients:
self.statestore.set_client({"name": client["name"], "status": "offline"})

self.modelservice = ModelService()

# Create gRPC server
self.server = Server(self, self.modelservice, grpc_config)

Expand Down Expand Up @@ -600,6 +610,10 @@ def TaskStream(self, response, context):

self._send_status(status)

# Set client status to online
self.clients[client.name]["status"] = "online"
self.statestore.set_client({"name": client.name, "status": "online"})

# Keep track of the time context has been active
start_time = time.time()
while context.is_active():
Expand Down

0 comments on commit 368850b

Please sign in to comment.