Implement Vercel Queue SDK#158
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
0ca208c to
24f7b5d
Compare
24f7b5d to
8c9f5f0
Compare
There was a problem hiding this comment.
I think we need a first class primitive for running the subscriber outside of vercel in poll mode, something like:
from vercel.queue import subscribe, subscriber
@subscribe(topic="orders", retry_after=60)
async def fulfill(order: dict[str, str]) -> None:
await process(order)
if __name__ == "__main__":
subscriber.poll(region="iad1")You shouldn't need anything more than those 2 lines to migrate out of vercel
|
I also don't think consumer groups should be required, this should be the minimal example: from vercel.queue import subscribe, subscriber
@subscribe(topic="orders")
async def fulfill(order: dict[str, str]) -> None:
await process(order)And in cases where you do want to explicitly set it, like for poll mode, the examples shouldn't require basing it off of the file name and sanitizing it. The DX I'd want is: from vercel.queue import subscribe, subscriber
@subscribe(topic="orders", consumer="a")
async def fulfill(order: dict[str, str]) -> None:
await process(order) |
|
I think exposing Ideally, I'd want the user-facing code to look like this:
from vercel.queue import subscribe, Subscriber
@subscribe(topic="orders")
async def fulfill_order(order: dict[str, str]) -> None:
await process_order(order)
# app = asgi_app() # <- leaks implementation details
subscriber = Subscriber() # <- this can have a get_asgi_app() method that we can look for in the runtime
if __name__ == "__main__":
subscriber.poll(region="iad1")And config can look like: [[tool.vercel.subscribers]]
entrypoint = "worker:subscriber"or if we don't like from vercel.queue import subscribe, subscriber
@subscribe(topic="orders")
async def fulfill_order(order: dict[str, str]) -> None:
await process_order(order)
# app = asgi_app() # <- not requiredconfig: [[tool.vercel.subscribers]]
entrypoint = "worker.py" # we bootstrap the asgi app in the runtime
# worker.py just needs to import all the subscribe tasks |
| ```json | ||
| { | ||
| "functions": { | ||
| "api/queue.py": { |
There was a problem hiding this comment.
It's good that this works and it definitely should, but let's not teach the LLMs to do this, I'd rather commit to [[tool.vercel.subscribers]] from the beginning and use that in the README and docs and examples
There was a problem hiding this comment.
also functions is a footgun since it creates a function for every entry (and it can be a glob)
Ideally we'd want to be able to control how we pack subscribers into functions
There was a problem hiding this comment.
Yeah, I oscillated between publishing something that is less optimal and works now and can be tested vs something that is better but doesn't work in this PR. The plan is to release vercel.queue with proper documentation for subscribers (and coordinate the release with the landing of that).
The asgi_app thing is temporary so that we can test this impl with plain |
Introduce `vercel-queue`, a Python client for publishing to and consuming from the Vercel Queues API. Features: - **Simple API surface**: `send()`, `@subscribe`, and `poll()` - **Customizable Clients**: configurable `QueueQlient` - **Full async/sync support**: async first, import the same API through `vercel.queue.sync` - **Type Safety**: `Topic[T]`, typed messages, and optional Pydantic validation - **Zero-copy streaming**: subscribers can be typed to receive `AsyncIterator[bytes]` in which case the byte stream is passed along from the incoming message HTTP stream directly without copying or extra buffering - **Automatic message lifecycle**: messages are automatically acknowledged on successful handler exit; message lease is automatically extended while the handler is running - **Customizable Serialization**: built-in JSON, text, binary, and streaming transports, ability to define and use custom transports - **Local Development Support**: complete local queue server emulator that can be used both in-process and as a standalone local server process for testing and development. See `README.md` for more details.
8c9f5f0 to
0c68047
Compare
Added |
I adjusted most examples to avoid setting explicit group names. For plain |
Introduce
vercel-queue, a Python client for publishing to and consuming fromthe Vercel Queues API.
Features:
send(),@subscribe, andpoll()QueueQlientvercel.queue.syncTopic[T], typed messages, and optional Pydantic validationAsyncIterator[bytes]in which case the byte stream is passed alongfrom the incoming message HTTP stream directly without copying or
extra buffering
acknowledged on successful handler exit; message lease is
automatically extended while the handler is running
transports, ability to define and use custom transports
be used both in-process and as a standalone local server process for
testing and development.
See
README.mdfor more details.