From 4c0bafa7cf2b913792672c34acf6891ff1ee93ee Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Thu, 12 Jun 2025 12:28:21 +0300 Subject: [PATCH] fix --- main.py | 75 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/main.py b/main.py index 53c2af7..cc1d83d 100644 --- a/main.py +++ b/main.py @@ -104,46 +104,47 @@ def update_host(host: str) -> str | None: return None -while True: - now = datetime.datetime.now() - mongo_hosts = mongo.hosts - hosts = get_hosts() - print(f"got hosts {hosts}") - updated = False - for host in hosts: - if ( - now + datetime.timedelta(days=14) - > mongo_hosts.get( - host, {"expire_time": datetime.datetime.fromtimestamp(1)} - )["expire_time"] - ): - success = update_host(host) - if success: - print(success) - send_notification( - f"host {host} was not updated with an error: {success}" +if __name__ == "__main__": + while True: + now = datetime.datetime.now() + mongo_hosts = mongo.hosts + hosts = get_hosts() + print(f"got hosts {hosts}") + updated = False + for host in hosts: + if ( + now + datetime.timedelta(days=14) + > mongo_hosts.get( + host, {"expire_time": datetime.datetime.fromtimestamp(1)} + )["expire_time"] + ): + success = update_host(host) + if success: + print(success) + send_notification( + f"host {host} was not updated with an error: {success}" + ) + else: + mongo.update_date(host) + updated = True + send_notification(f"host {host} updated") + else: + print(f"Host {host} does not need to be updated") + if updated: + if os.getenv("STAGE") == "development": + container_id_run = call( + "echo $(docker ps -q -f name=infra-development_nginx)" ) else: - mongo.update_date(host) - updated = True - send_notification(f"host {host} updated") - else: - print(f"Host {host} does not need to be updated") - if updated: - if os.getenv("STAGE") == "development": - container_id_run = call( - "echo $(docker ps -q -f name=infra-development_nginx)" - ) - else: - container_id_run = call("echo $(docker ps -q -f name=infra_nginx)") + container_id_run = call("echo $(docker ps -q -f name=infra_nginx)") - print(container_id_run.code, container_id_run.out, container_id_run.err) + print(container_id_run.code, container_id_run.out, container_id_run.err) - command = f"docker exec {container_id_run.out.strip()} ./refre.sh" - print(command) + command = f"docker exec {container_id_run.out.strip()} ./refre.sh" + print(command) - restart = call(command) - print(restart.code, restart.out, restart.err) - send_notification(f"Balancer for {os.getenv("STAGE")} was restarted") + restart = call(command) + print(restart.code, restart.out, restart.err) + send_notification(f"Balancer for {os.getenv("STAGE")} was restarted") - time.sleep(30) + time.sleep(30)