mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 14:44:21 +01:00
plugin - small changes
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user