From 70f3159a2a4a56439d4d4938e538f53846bab9b7 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 21 Nov 2023 13:51:42 -0800 Subject: [PATCH] refactor(rq_worker.py): put rq worker behind function call (prevent default import) --- litellm/proxy/queue/rq_worker.py | 35 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/litellm/proxy/queue/rq_worker.py b/litellm/proxy/queue/rq_worker.py index 86e1ebf7613..eae4e93b816 100644 --- a/litellm/proxy/queue/rq_worker.py +++ b/litellm/proxy/queue/rq_worker.py @@ -1,6 +1,4 @@ import sys, os -from rq import Worker, Queue, Connection -from redis import Redis from dotenv import load_dotenv load_dotenv() # Add the path to the local folder to sys.path @@ -8,23 +6,16 @@ sys.path.insert( 0, os.path.abspath("../../..") ) # Adds the parent directory to the system path - for litellm local dev - -# # Import your local module -# import litellm -# from litellm import litellm_queue_completion - -# Set up RQ connection -redis_conn = Redis(host=os.getenv("REDIS_HOST"), port=os.getenv("REDIS_PORT"), password=os.getenv("REDIS_PASSWORD")) -print(redis_conn.ping()) # Should print True if connected successfully -# Create a worker and add the queue -try: - queue = Queue(connection=redis_conn) - worker = Worker([queue], connection=redis_conn) -except Exception as e: - print(f"Error setting up worker: {e}") - exit() - -# Run the worker -if __name__ == '__main__': - with Connection(redis_conn): - worker.work() \ No newline at end of file +def start_rq_worker(): + from rq import Worker, Queue, Connection + from redis import Redis + # Set up RQ connection + redis_conn = Redis(host=os.getenv("REDIS_HOST"), port=os.getenv("REDIS_PORT"), password=os.getenv("REDIS_PASSWORD")) + print(redis_conn.ping()) # Should print True if connected successfully + # Create a worker and add the queue + try: + queue = Queue(connection=redis_conn) + worker = Worker([queue], connection=redis_conn) + except Exception as e: + print(f"Error setting up worker: {e}") + exit() \ No newline at end of file