Skip to content

Test redis direct connection, fallback to docker if failed #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down