plugin - small changes

This commit is contained in:
Sergi Delgado Segura
2020-05-05 15:11:36 +02:00
parent 8704dcf2b9
commit b650ba3c26
2 changed files with 7 additions and 9 deletions

View File

@@ -10,6 +10,10 @@ from exceptions import TowerConnectionError, TowerResponseError
MAX_RETRIES = None MAX_RETRIES = None
def check_retry(status):
return status == "temporarily unreachable"
def on_backoff(details): def on_backoff(details):
plugin = details.get("args")[1] plugin = details.get("args")[1]
tower_id = details.get("args")[2] tower_id = details.get("args")[2]
@@ -47,15 +51,9 @@ class Retrier:
Thread(target=self.do_retry, args=[plugin, tower_id, tower], daemon=True).start() Thread(target=self.do_retry, args=[plugin, tower_id, tower], daemon=True).start()
@backoff.on_predicate( @backoff.on_predicate(backoff.expo, check_retry, max_tries=max_retries, on_backoff=on_backoff, on_giveup=on_giveup)
backoff.expo,
lambda x: x == "temporarily unreachable",
max_tries=max_retries,
on_backoff=on_backoff,
on_giveup=on_giveup,
)
def do_retry(self, plugin, tower_id, tower): def do_retry(self, plugin, tower_id, tower):
for appointment_dict, signature in plugin.wt_client.towers[tower_id]["pending_appointments"]: for appointment_dict, signature in plugin.wt_client.towers[tower_id].pending_appointments:
tower_update = {} tower_update = {}
try: try:
tower_signature, available_slots = add_appointment(plugin, tower_id, tower, appointment_dict, signature) tower_signature, available_slots = add_appointment(plugin, tower_id, tower, appointment_dict, signature)

View File

@@ -84,7 +84,7 @@ def init_tower():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config["general"] = {"max_retries": "5"} config["general"] = {"max_retries": "5"}
os.makedirs(os.environ["TOWERS_DATA_DIR"]) os.makedirs(os.environ["TOWERS_DATA_DIR"], exist_ok=True)
with open(os.path.join(os.environ["TOWERS_DATA_DIR"], "watchtower.conf"), "w") as configfile: with open(os.path.join(os.environ["TOWERS_DATA_DIR"], "watchtower.conf"), "w") as configfile:
config.write(configfile) config.write(configfile)