fariedalfarizi's picture
Add profanity detection feature with 150+ Indonesian/English words
c7e434a
"""
RQ Worker
Run this to start the background worker
"""
import time
import sys
from rq import Worker
from app.core.redis_client import get_redis_connection, get_queue, check_redis_connection
from app.config import settings
def run_worker():
"""Run RQ worker with retry logic"""
print(f"πŸ”„ Starting RQ Worker...")
print(f"πŸ“Š Queue: {settings.QUEUE_NAME}")
print(f"πŸ”— Redis: {settings.REDIS_HOST}:{settings.REDIS_PORT}")
# Wait for Redis to be ready
max_retries = 30
retry_interval = 2
for attempt in range(1, max_retries + 1):
is_connected, error_msg = check_redis_connection()
if is_connected:
print(f"βœ… Redis connected!")
break
else:
if attempt < max_retries:
print(f"⏳ Waiting for Redis... (attempt {attempt}/{max_retries})")
time.sleep(retry_interval)
else:
print(f"❌ Failed to connect to Redis after {max_retries} attempts")
print(f" Error: {error_msg}")
sys.exit(1)
# Start worker
redis_conn = get_redis_connection()
queue = get_queue()
print(f"πŸš€ Worker ready and listening for tasks!\n")
worker = Worker([queue], connection=redis_conn)
worker.work()
if __name__ == "__main__":
run_worker()