Queues
Send work to a queue from your app and process it in the background, with retries and a dead-letter queue.
On this page
A queue holds messages until a consumer processes them. Use it for anything that should not make a visitor wait: sending e-mails, resizing images, printing kitchen tickets, importing a file.
[run.apps.laespiga.queues.kitchen]
consumer = "workers/kitchen.ts"
batch = 10
retries = 5 # attempts in all, 1 to 20 (5 when left out)
concurrency = 4// in your app
import { queue } from '@sypnia/run/queue';
await queue('kitchen').send({ order: 1042 }, { delaySeconds: 0, dedupeId: 'order-1042' });
// workers/kitchen.ts
import { consumer } from '@sypnia/run/queue';
export default consumer<{ order: number }>(async (messages) => {
for (const m of messages) await printTicket(m.body.order);
});How it behaves
- Each queue is an Amazon SQS queue of the app’s environment, with a dead-letter queue next to it.
- A batch that throws is tried again with growing waits: 5 attempts in all by default, or what
retriessays (1 to 20). After the last attempt its messages move to the dead-letter queue, whererun queues dlq kitchenlists them and--replaysends them back. - Delivery is at least once: process messages so that receiving one twice does no harm (
dedupeIddrops duplicates sent within five minutes). delaySecondsholds a message up to 15 minutes before it can be received.- Consumers scale with the queue’s length up to
concurrency.
Limits from AWS
A message body is up to 256 KB; put bigger payloads in Sypnia Files and send the path.