fix #56
75
main.py
75
main.py
@ -104,46 +104,47 @@ def update_host(host: str) -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
while True:
|
if __name__ == "__main__":
|
||||||
now = datetime.datetime.now()
|
while True:
|
||||||
mongo_hosts = mongo.hosts
|
now = datetime.datetime.now()
|
||||||
hosts = get_hosts()
|
mongo_hosts = mongo.hosts
|
||||||
print(f"got hosts {hosts}")
|
hosts = get_hosts()
|
||||||
updated = False
|
print(f"got hosts {hosts}")
|
||||||
for host in hosts:
|
updated = False
|
||||||
if (
|
for host in hosts:
|
||||||
now + datetime.timedelta(days=14)
|
if (
|
||||||
> mongo_hosts.get(
|
now + datetime.timedelta(days=14)
|
||||||
host, {"expire_time": datetime.datetime.fromtimestamp(1)}
|
> mongo_hosts.get(
|
||||||
)["expire_time"]
|
host, {"expire_time": datetime.datetime.fromtimestamp(1)}
|
||||||
):
|
)["expire_time"]
|
||||||
success = update_host(host)
|
):
|
||||||
if success:
|
success = update_host(host)
|
||||||
print(success)
|
if success:
|
||||||
send_notification(
|
print(success)
|
||||||
f"host {host} was not updated with an error: {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:
|
else:
|
||||||
mongo.update_date(host)
|
container_id_run = call("echo $(docker ps -q -f name=infra_nginx)")
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user