anystore.interface.queue
Queue
Bases: Tags, Generic[T]
Simple queue interface to store and potentially notify distributed consumers across the file-like system (or any other anystore backend). This is not intended to be a super efficient and/or complex queue-worker implementation, more like an interface to store "tags" that contain some payload that another service can check out later. The queue is typed, given that store and retrieve data is expected to have that strict type.
Source code in anystore/interface/queue.py
__call__(value)
checkout()
Checkout the next item in queue (no order guaranteed).
If an exception is thrown within the context, the item is not removed from the queue. Yields None if the queue is empty.
Example
```python while True: with queue.checkout() as payload: if payload is None: break do_something(payload)
Source code in anystore/interface/queue.py
consume()
Continuously consume items from the queue until empty.
Each item is automatically removed after successful processing. If an exception occurs while processing an item, it remains in the queue.
Yields:
| Type | Description |
|---|---|
T
|
Queue items one by one until the queue is empty |
Source code in anystore/interface/queue.py
get(key)
Get a value from the queue for the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The typed value for the key, or None if not found |
Source code in anystore/interface/queue.py
put(value)
Store a value at a uuid7 key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The typed content to store |
required |
Queues
Bases: Generic[T]
A collection of named queues with a common type and prefix.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
type[T]
|
The type of items stored in the queues |
required |
uri
|
Uri
|
Base URI for the queues |
required |
actions
|
list[str]
|
List of action/queue names |
required |
Source code in anystore/interface/queue.py
get_queue(t, *args, **kwargs)
Get a typed queue instance.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
type[T]
|
The type of items stored in the queue (used as model for Pydantic types) |
required |
*args
|
Arguments passed to |
()
|
|
**kwargs
|
Keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Queue[T]
|
A typed Queue instance |