Queue
Queue provides a flexible, reliable means of managing a stream of data within your application. Users can effortlessly enqueue string format messages, ensuring that no data is lost or overlooked. Later, these messages can be consumed at a pace that suits the workflow, offering a seamless integration of production and consumption processes.
By default, the Queue object acts as a single FIFO queue which supports send, receive, and length operations.
If you are using python SDK to access queue, make sure you are logged in via lep login
command with the workspace token. You can find it under settings page
Queue Management
Create Queue
To initialize and set up a new queue for storing and managing data, you can do this via WebUI or Python SDK.
1. WebUI
- Go to the Storage tab, and click on Queue.
- Click on New Queue.
- Enter the queue name and click on Create. The queue creation is an asynchronous operation, and it may take a few seconds to complete.
2. Python SDK
from leptonai.queue import Queue
# Craete queue
my_queue = Queue("somequeue", create_if_not_exists=True)
List Queues
1. WebUI
- Go to the Storage tab, and click on Queue.
- You can see the list of queues available in the workspace.
2. Python SDK
from leptonai.queue import Queue
# List queues
my_queue = Queue.list_queue()
# this will return a queue name
Delete Queue
1. WebUI
- Go to the Storage tab, and click on Queue.
- Click on the dot icon on the right side of the queue name, and click it to see the delete option.
2. Python SDK
from leptonai.queue import Queue
# List queues
my_queue = Queue.delete_queue("somequeue")
Queue Operations
Queue operations can only be performed using the Python SDK. If you are looking to perform queue operations using other forms, please contact us.
Send message to a queue
Add new messages to a queue for processing or storage.
from leptonai.queue import Queue
# Fetch the queue by name
my_queue = Queue("somequeue", create_if_not_exists=True)
# Send message to the queue
my_queue.send('this is a message')
Receive message from a queue
Retrieve messages waiting in the queue.
from leptonai.queue import Queue
# Fetch the queue by name
my_queue = Queue("somequeue", create_if_not_exists=True)
# Send message to the queue
my_queue.receive()
Get Queue Length
Find out how to quickly retrieve the number of items currently waiting in the queue.
from leptonai.queue import Queue
# Get length of a queue
Queue.length('somequeue')