From d6ad156061f175213122dc4dfbf2322a2fba7e7a Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Sun, 29 Sep 2019 04:30:17 +1000 Subject: Poll the database a maximum of 10 attempts before exit code 1. --- manage.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'manage.py') diff --git a/manage.py b/manage.py index baf7333a..44435de5 100755 --- a/manage.py +++ b/manage.py @@ -96,7 +96,9 @@ class SiteManager: # Attempt to connect to the database socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - while True: + + attempts_left = 10 + while attempts_left: try: # Ignore 'incomplete startup packet' s.connect((domain, port)) @@ -104,8 +106,12 @@ class SiteManager: print("Database is ready.") break except socket.error: + attempts_left -= 1 print("Not ready yet, retrying.") time.sleep(0.5) + else: + print("Database could not be found, exiting.") + sys.exit(1) def prepare_server(self) -> None: """Perform preparation tasks before running the server.""" -- cgit v1.2.3