Queue Operations (sdk.queue)

Managed background job processing for long-running tasks.

Introduction

import { AerostackServer } from '@aerostack/sdk';
 
const sdk = new AerostackServer(env);
await sdk.queue.enqueue({ type: 'email', data: { to: '[email protected]' } });

Features

enqueue(job)

Send a job to the configured Cloudflare Queue.

  • type: Job type string (e.g., ‘email’, ‘resize-image’).
  • data: Any JSON object.
  • delay: Optional delay in seconds.
await sdk.queue.enqueue({
  type: 'resize-image',
  data: { width: 800, height: 600, key: 'uploads/123.jpg' },
  delay: 10 // Retry later if needed
});

getStatus(jobId)

(Future) Check the status of a specific job.

Configure [[queues]] with binding QUEUE in aerostack.toml.

Worker Implementation

Implement the consumer in your Worker:

export default {
  async queue(batch, env) {
    for (const msg of batch.messages) {
      if (msg.body.type === 'email') {
        // process email
      }
      msg.ack();
    }
  }
}