Skip to content

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.

A Queue can split into partitions, each with its own items in order. A consumer takes from one partition and never sees another’s:

ApiWorkerputJobs · Modal Queuesamanalinttakentestbuildtakendeploysession-samSandboxsession-anaSandboxApiWorkerputJobs · Modal Queuesamanalinttakentestbuildtakendeploysession-samSandboxsession-anaSandbox
The Worker puts each user's tasks in that user's partition. session-sam has taken lint, and test waits behind it; session-ana never sees either.
src/Storage.ts
import * as Modal from "@alchemy.run/modal";
export const Jobs = Modal.Queue("Jobs", {});
const jobs = yield* Modal.WriteQueue(Jobs);
yield* jobs.put({ repo: "alchemy-run/alchemy", command: "pnpm test" });

Provide Modal.WriteQueueHttp.

const jobs = yield* Modal.ReadQueue(Jobs);
const batch = yield* jobs.take({ count: 10, timeout: "5 seconds" });

take removes items. peek reads them without removing.

yield* jobs.put(task, { partition: user });
const mine = yield* jobs.take({ partition: user });