Compare commits

..

No commits in common. "23cb51985ce511ee5f569676e0bd02bff5094bc6" and "0c5ce6c1eb7594e01c10a1ad10fcd10bc5a01843" have entirely different histories.

75
main.py
View File

@ -104,47 +104,46 @@ def update_host(host: str) -> str | None:
return None return None
if __name__ == "__main__": while True:
while True: now = datetime.datetime.now()
now = datetime.datetime.now() mongo_hosts = mongo.hosts
mongo_hosts = mongo.hosts hosts = get_hosts()
hosts = get_hosts() print(f"got hosts {hosts}")
print(f"got hosts {hosts}") updated = False
updated = False for host in hosts:
for host in hosts: if (
if ( now + datetime.timedelta(days=14)
now + datetime.timedelta(days=14) > mongo_hosts.get(
> mongo_hosts.get( host, {"expire_time": datetime.datetime.fromtimestamp(1)}
host, {"expire_time": datetime.datetime.fromtimestamp(1)} )["expire_time"]
)["expire_time"] ):
): success = update_host(host)
success = update_host(host) if success:
if success: print(success)
print(success) send_notification(
send_notification( f"host {host} was not updated with an error: {success}"
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: else:
container_id_run = call("echo $(docker ps -q -f name=infra_nginx)") 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)")
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" command = f"docker exec {container_id_run.out.strip()} ./refre.sh"
print(command) print(command)
restart = call(command) restart = call(command)
print(restart.code, restart.out, restart.err) print(restart.code, restart.out, restart.err)
send_notification(f"Balancer for {os.getenv("STAGE")} was restarted") send_notification(f"Balancer for {os.getenv("STAGE")} was restarted")
time.sleep(30) time.sleep(30)