Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a doc string to get-list-details function #240

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion API/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_queue_info():
return JSONResponse(content=queue_info)


@router.get("/queue/details/{queue_name}/")
@router.get("/queue/details/{queue_name}/", tags=["Queue"], summary="Get details of items in a queue")
@version(1)
def get_list_details(
queue_name: str,
Expand All @@ -185,15 +185,31 @@ def get_list_details(
description="Includes arguments of task",
),
):
"""
Get details of items in the specified queue.

:param queue_name: Name of the queue to retrieve details from.
:type queue_name: str
:param args: Flag to include arguments of the task (default is False).
:type args: bool
:raises HTTPException 404: If the specified queue is not found.
:returns: List of items in the queue with their details.
:rtype: List[Dict[str, Any]]
"""
# Check if the specified queue exists
if queue_name not in queues:
raise HTTPException(status_code=404, detail=f"Queue '{queue_name}' not found")

# Connect to Redis
redis_client = redis.StrictRedis.from_url(CELERY_BROKER_URL)

# Retrieve items from the queue
list_items = redis_client.lrange(queue_name, 0, -1)

# Convert bytes to strings
list_items = [item.decode("utf-8") for item in list_items]

# Extract details of each item
items_details = [
{
"index": index,
Expand Down