Refactor send_file_to_bunkerweb function to improve instance status handling and simplify control flow

This commit is contained in:
Théophile Diot 2024-10-30 14:21:44 +01:00
parent 804937207a
commit 7db2dadf7f
No known key found for this signature in database
GPG key ID: FA995104A0BA376A

View file

@ -178,24 +178,19 @@ def send_file_to_bunkerweb(file_path: Path, endpoint: str):
break
status = responses.get(db_instance["hostname"], {"status": "down"}).get("status", "down")
if status == "success":
success = True
elif index != -1:
fails.append(db_instance["hostname"])
ret = SCHEDULER.db.update_instance(db_instance["hostname"], "up" if status == "success" else "down")
if ret:
LOGGER.error(f"Couldn't update instance {db_instance['hostname']} status to down in the database: {ret}")
if status == "success":
if index == -1:
with SCHEDULER_LOCK:
with SCHEDULER_LOCK:
if status == "success":
success = True
if index == -1:
LOGGER.debug(f"Adding {db_instance['hostname']}:{db_instance['port']} to the list of reachable instances")
SCHEDULER.apis.append(API(f"http://{db_instance['hostname']}:{db_instance['port']}", db_instance["server_name"]))
continue
with SCHEDULER_LOCK:
if api.endpoint == f"http://{db_instance['hostname']}:{db_instance['port']}/":
elif index != -1:
fails.append(f"{db_instance['hostname']}:{db_instance['port']}")
LOGGER.debug(f"Removing {db_instance['hostname']}:{db_instance['port']} from the list of reachable instances")
del SCHEDULER.apis[index]