Add method to get swarm participants for new leader, fix some comments

This commit is contained in:
DSTO\pivatom
2019-01-14 11:19:27 +10:30
parent 90d096a918
commit 3c978b3ca3

View File

@@ -27,13 +27,13 @@ class Commander:
# If using apache zookeeper this won't be needed.
def make_decision(self):
# Should change this to be a strategy, for different implementations of making
# a decision on the votes.
# Should change this to follow strategy pattern, for different implementations of
# making a decision on the votes.
votes = self._votes
dif_votes = {}
for vote in votes:
# Get the average/max, etc.
# Get the count of different votes.
if str(vote) in dif_votes:
dif_votes[str(vote)] = dif_votes[str(vote)] + 1
else:
@@ -49,6 +49,7 @@ class Commander:
return max_vote
def get_votes(self):
# Should consider abstracting these messages to another class for portability.
message = {"type": "reqVote"}
message_packed = umsgpack.packb(message)
self._taking_votes = True
@@ -72,7 +73,7 @@ class Commander:
# Commander must have requested their taking votes, and the timeout
# has not occurred.
# Only add vote to list if the client has not already voted.
if messageDict["client"] not in self._votes.keys:
if messageDict["client"] not in self._votes:
self._votes[messageDict["client"]] = messageDict["vote"]
elif messageDict["type"] == "disconnected":
@@ -83,3 +84,7 @@ class Commander:
def on_connect(self, client, userdata, flags, rc):
self.client.subscribe("swarm1/commander")
def get_participants(self):
self.client.publish("swarm1/voters")