From 98dc22aeda0e27ccbfb82dbfc9b4c784fdfaafe7 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 10 Apr 2020 01:03:55 -0400 Subject: [PATCH] bug fixes --- o_manager.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/o_manager.py b/o_manager.py index 6d496f7..54aad16 100644 --- a/o_manager.py +++ b/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: