Skip to content
Open
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ 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 = "localhost" # or use any custom host if required
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded redis_host value does not use environment variables or settings that are used elsewhere in the codebase.

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 +89,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 Expand Up @@ -317,4 +327,4 @@ def main():


if __name__ == "__main__":
main()
main()