Add method to get swarm participants for new leader, fix some comments
This commit is contained in:
@@ -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":
|
||||
@@ -82,4 +83,8 @@ class Commander:
|
||||
pass
|
||||
|
||||
def on_connect(self, client, userdata, flags, rc):
|
||||
self.client.subscribe("swarm1/commander")
|
||||
self.client.subscribe("swarm1/commander")
|
||||
|
||||
def get_participants(self):
|
||||
|
||||
self.client.publish("swarm1/voters")
|
||||
Reference in New Issue
Block a user