Queue
Aerostack Queue provides background job processing backed by Cloudflare Queues. Jobs are automatically retried on failure with configurable backoff.
Quick start
import { sdk } from '@aerostack/sdk'
// Enqueue a job
await sdk.queue.send('email:send', {
to: '[email protected]',
subject: 'Welcome to our app!',
templateId: 'welcome',
userId: '123',
})Enqueue jobs
// Simple job
await sdk.queue.send('job-type', payload)
// With delay (seconds)
await sdk.queue.send('reminder:send', { userId: '123' }, {
delaySeconds: 3600, // send in 1 hour
})
// With custom retry policy
await sdk.queue.send('webhook:deliver', { url, body }, {
maxRetries: 5,
retryDelay: 30,
})Process jobs
Define consumers in your Worker’s queue handler:
// In your Worker (wrangler.toml must declare the queue binding)
export default {
async queue(batch, env) {
for (const message of batch.messages) {
const { type, payload } = message.body
if (type === 'email:send') {
await sendEmail(payload)
message.ack()
}
if (type === 'webhook:deliver') {
const ok = await deliverWebhook(payload.url, payload.body)
if (ok) {
message.ack()
} else {
message.retry({ delaySeconds: 60 })
}
}
}
}
}Fan-out pattern
Send the same job to multiple workers:
await Promise.all([
sdk.queue.send('notification:email', { userId, event }),
sdk.queue.send('notification:push', { userId, event }),
sdk.queue.send('analytics:track', { userId, event }),
])Queue jobs are durable — they survive Worker crashes and restarts. If your Worker fails to process a job, it will be retried automatically.