bug fixes
This commit is contained in:
parent
25c4218ff6
commit
98dc22aeda
15
o_manager.py
15
o_manager.py
@ -120,6 +120,7 @@ class OManager:
|
||||
print("lb_cmd", lb_cmd)
|
||||
self.run_task.append(self.loop.create_task(
|
||||
self.run_cmd(lb_cmd)))
|
||||
#print("pre calc weights:", self.calc_weights())
|
||||
self.run_task.append(self.loop.create_task(
|
||||
self.keep_applying_weights()))
|
||||
|
||||
@ -131,25 +132,32 @@ class OManager:
|
||||
ping_stat = i["op"].get_ping_stat(
|
||||
).splitlines()[-max(n_up, n_down):]
|
||||
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
|
||||
|
||||
print("ping status:", ping_stat)
|
||||
def all_equal(n, status):
|
||||
for j in range(n):
|
||||
if ping_stat[-j] != status:
|
||||
for j in range(min(n, len(ping_stat))):
|
||||
if ping_stat[-(j+1)] != status:
|
||||
return False
|
||||
return True
|
||||
# all up
|
||||
if all_equal(n_up, True):
|
||||
i["weight"] = 1
|
||||
print("all_up")
|
||||
if all_equal(n_down, False):
|
||||
i["weight"] = 0
|
||||
print("all_down")
|
||||
|
||||
weights.append(i["weight"])
|
||||
return weights
|
||||
|
||||
async def keep_applying_weights(self):
|
||||
old_weights = []
|
||||
while True:
|
||||
await asyncio.sleep(5)
|
||||
print("calculating weights")
|
||||
new_weights = self.calc_weights()
|
||||
print("finished calc")
|
||||
if old_weights != new_weights:
|
||||
old_weights = new_weights
|
||||
print("weight changed, new weights:", new_weights)
|
||||
try:
|
||||
self.generate_dynamic_weight(
|
||||
@ -159,7 +167,6 @@ class OManager:
|
||||
print("error applying weights")
|
||||
else:
|
||||
print("weight not changed, weights:", new_weights)
|
||||
await asyncio.sleep(5)
|
||||
|
||||
async def run_cmd(self, cmd):
|
||||
while True:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user