From c63249b778471daa9f891ce7163fa9352b086bc3 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 23 Mar 2023 11:58:33 +0700 Subject: [PATCH] faster check on restart only, sleep before CommandError --- tubearchivist/config/management/commands/ta_connection.py | 8 ++++++-- tubearchivist/config/management/commands/ta_startup.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tubearchivist/config/management/commands/ta_connection.py b/tubearchivist/config/management/commands/ta_connection.py index 4f6b8c31..a6159b3c 100644 --- a/tubearchivist/config/management/commands/ta_connection.py +++ b/tubearchivist/config/management/commands/ta_connection.py @@ -43,7 +43,6 @@ class Command(BaseCommand): self.stdout.write("[1] connect to Redis") redis_conn = RedisArchivist().conn for _ in range(5): - sleep(2) try: pong = redis_conn.execute_command("PING") if pong: @@ -54,10 +53,12 @@ class Command(BaseCommand): except Exception: # pylint: disable=broad-except self.stdout.write(" ... retry Redis connection") + sleep(2) message = " 🗙 Redis connection failed" self.stdout.write(self.style.ERROR(f"{message}")) RedisArchivist().exec("PING") + sleep(60) raise CommandError(message) def _redis_config_set(self): @@ -75,13 +76,13 @@ class Command(BaseCommand): self.stdout.write("[3] connect to Elastic Search") total = self.TIMEOUT // 5 for i in range(total): - sleep(5) self.stdout.write(f" ... waiting for ES [{i}/{total}]") try: _, status_code = ElasticWrap("/").get( timeout=1, print_error=False ) except requests.exceptions.ConnectionError: + sleep(5) continue if status_code and status_code == 200: @@ -98,6 +99,7 @@ class Command(BaseCommand): self.stdout.write(self.style.ERROR(f"{message}")) self.stdout.write(f" error message: {response}") self.stdout.write(f" status code: {status_code}") + sleep(60) raise CommandError(message) def _es_version_check(self): @@ -118,6 +120,7 @@ class Command(BaseCommand): + f"Expected {self.MIN_MAJOR}.{self.MIN_MINOR} but got {version}" ) self.stdout.write(self.style.ERROR(f"{message}")) + sleep(60) raise CommandError(message) def _es_path_check(self): @@ -137,4 +140,5 @@ class Command(BaseCommand): + " path.repo=/usr/share/elasticsearch/data/snapshot" ) self.stdout.write(self.style.ERROR(f"{message}")) + sleep(60) raise CommandError(message) diff --git a/tubearchivist/config/management/commands/ta_startup.py b/tubearchivist/config/management/commands/ta_startup.py index 0b40a2bf..bba4eff8 100644 --- a/tubearchivist/config/management/commands/ta_startup.py +++ b/tubearchivist/config/management/commands/ta_startup.py @@ -191,4 +191,5 @@ class Command(BaseCommand): message = f" 🗙 {index_name} vid_type update failed" self.stdout.write(self.style.ERROR(message)) self.stdout.write(response) + sleep(60) raise CommandError(message)