You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Minor Changes
Added
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"typeEmailPayload={to: string;body: string}typeEmailResult={ok: boolean}constadapter=newMemoryQueueAdapter()constqueue=newQueue<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 jobsawaitsendBulkEmails(jobs.map((j)=>j.payload))returnjobs.map(()=>({ok: true}))})// Add jobs as usualawaitqueue.addJobs("send-emails",[{to: "a@example.com",body: "Hi A"},{to: "b@example.com",body: "Hi B"},// ...])queue.start()