mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
refactor(proxy_server.py): refactoring background rq worker
This commit is contained in:
parent
7c79d10e9f
commit
a1f6b9b531
4 changed files with 52 additions and 43 deletions
30
litellm/proxy/queue/rq_worker.py
Normal file
30
litellm/proxy/queue/rq_worker.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue