Queues
A Queue hands work from whoever puts it to whoever takes it: a Worker, a Sandbox, a Function or Python code. Items are JSON and expire 24 hours after they’re put.
Partitions keep each user’s work apart
Section titled “Partitions keep each user’s work apart”A Queue can split into partitions, each with its own items in order. A consumer takes from one partition and never sees another’s:
Declare a Queue
Section titled “Declare a Queue”import * as Modal from "@alchemy.run/modal";
export const Jobs = Modal.Queue("Jobs", {});Put work on it
Section titled “Put work on it”const jobs = yield* Modal.WriteQueue(Jobs);yield* jobs.put({ repo: "alchemy-run/alchemy", command: "pnpm test" });Provide Modal.WriteQueueHttp.
Take work off it
Section titled “Take work off it”const jobs = yield* Modal.ReadQueue(Jobs);const batch = yield* jobs.take({ count: 10, timeout: "5 seconds" });take removes items. peek reads them without removing.
Put and take by partition
Section titled “Put and take by partition”yield* jobs.put(task, { partition: user });const mine = yield* jobs.take({ partition: user });