diff --git a/start_server.py b/start_server.py index f914bbd1..323b603a 100644 --- a/start_server.py +++ b/start_server.py @@ -44,7 +44,21 @@ def wait_for_redis(host="localhost", port=6379, timeout=20): return False def check_and_start_redis(): - """Check if the Redis container is running, start if necessary.""" + """Check if the Redis service is available (via Docker or directly), and start the Docker container if necessary.""" + redis_host = os.environ.get("REDIS_HOST", "127.0.0.1") # or use any custom host if required + + try: + redis_port = int(os.getenv("REDIS_PORT", 6379)) + except ValueError: + logging.info("❌ Invalid REDIS_PORT value. Must be an integer. Defaulting to 6379.") + redis_port = 6379 + + # Try to connect directly to Redis + if wait_for_redis(host=redis_host, port=redis_port): + logging.info("Redis is already running and available.") + return # Return early if Redis is available + + # If not available, check if the Docker container is running or stopped try: # Check if container exists and is running check_running_cmd = ["docker", "ps", "-q", "-f", "name=morphik-redis"] @@ -80,6 +94,7 @@ def check_and_start_redis(): sys.exit(1) + def start_arq_worker(): """Start the ARQ worker as a subprocess.""" global worker_process