Skip to content

Conversation

noxify
Copy link
Owner

@noxify noxify commented Sep 25, 2025

  • Batch processing support: You can now register batch handlers via queue.registerBatch, allowing the queue to process multiple jobs at once according to configurable batch sizes and timing.
  • New batch configuration options: minSize, maxSize, and waitFor allow fine-grained control over when and how batches are processed.
  • Type-safe batch jobs: Batch jobs are strictly separated from scheduled/single jobs and do not support cron, delay, or repeat options.
  • Adapter API extended: All core adapters now support efficient batch operations.
  • Events for batch lifecycle: The queue emits batch:processing, batch:completed, and batch:failed events for batch jobs.

Handler exclusivity: A queue can handle only batch jobs or single jobs — not both. Attempting to register both handler types in the same queue will throw an error. This ensures clear and predictable processing.

Example

import { MemoryQueueAdapter, Queue } from "@vorsteh-queue/core"

type EmailPayload = { to: string; body: string }
type EmailResult = { ok: boolean }

const adapter = new MemoryQueueAdapter()
const queue = new Queue<EmailPayload, EmailResult>(adapter, {
  name: "batch-demo",
  batch: { minSize: 5, maxSize: 20, waitFor: 1000 },
})

queue.registerBatch("send-emails", async (jobs) => {
  // jobs is an array of up to 20 jobs
  await sendBulkEmails(jobs.map((j) => j.payload))
  return jobs.map(() => ({ ok: true }))
})

// Add jobs as usual
await queue.addJobs("send-emails", [
  { to: "[email protected]", body: "Hi A" },
  { to: "[email protected]", body: "Hi B" },
  // ...
])

queue.start()

Closes #29

Copy link

vercel bot commented Sep 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vorsteh-queue-docs Ready Ready Preview Comment Sep 25, 2025 10:22am

Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 5066d2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@vorsteh-queue/adapter-drizzle Minor
@vorsteh-queue/adapter-kysely Minor
@vorsteh-queue/adapter-prisma Minor
@vorsteh-queue/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@noxify noxify marked this pull request as draft September 25, 2025 08:04
Copy link

pkg-pr-new bot commented Sep 25, 2025

Open in StackBlitz

@vorsteh-queue/adapter-drizzle

npm i https://pkg.pr.new/noxify/vorsteh-queue/@vorsteh-queue/adapter-drizzle@37

@vorsteh-queue/adapter-kysely

npm i https://pkg.pr.new/noxify/vorsteh-queue/@vorsteh-queue/adapter-kysely@37

@vorsteh-queue/adapter-prisma

npm i https://pkg.pr.new/noxify/vorsteh-queue/@vorsteh-queue/adapter-prisma@37

@vorsteh-queue/core

npm i https://pkg.pr.new/noxify/vorsteh-queue/@vorsteh-queue/core@37

create-vorsteh-queue

npm i https://pkg.pr.new/noxify/vorsteh-queue/create-vorsteh-queue@37

commit: 5066d2f

@noxify noxify marked this pull request as ready for review September 25, 2025 10:07
@noxify noxify mentioned this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat]: Support batches
1 participant