The following code of get_queue_length gives queue length as zero all the time but when I run the same set of command in Django shell it works fine and gives total number of object in the queue
import os
import redis
from urllib.parse import urlparse
from celery.result import AsyncResult
from django.utils import timezone
from celery import states
broker_url = os.getenv('CELERY_BROKER_URL')
# Parse the broker URL
parsed_url = urlparse(broker_url)
# Extract the connection parameters
redis_host = parsed_url.hostname
redis_port = parsed_url.port
redis_db = int(parsed_url.path.lstrip('/'))
# Configure the Redis client
redis_client = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_db)
def get_queue_length(queue_name):
# Redis key for the queue
redis_key = f"{queue_name}"
return redis_client.llen(redis_key)
What can be reason for this issue? Am I missing something ?
So it turns out that redis_key = f"{queue_name}" was not being applied well! when I hardcoded redis_key = f"{'queue-name'}" this, it just worked fine, still dont know the reason why so
it turns out to be typo! MY Bad, closing this