|
1 | 1 | # @vorsteh-queue/core |
2 | 2 |
|
| 3 | +## 0.4.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- 66c4848: ### Added |
| 8 | + - 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. |
| 9 | + - New `batch` configuration options: `minSize`, `maxSize`, and `waitFor` allow fine-grained control over when and how batches are processed. |
| 10 | + - Type-safe batch jobs: Batch jobs are strictly separated from scheduled/single jobs and **do not support** cron, delay, or repeat options. |
| 11 | + - Adapter API extended: All core adapters now support efficient batch operations. |
| 12 | + - Events for batch lifecycle: The queue emits `batch:processing`, `batch:completed`, and `batch:failed` events for batch jobs. |
| 13 | + |
| 14 | + **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. |
| 15 | + |
| 16 | + #### Example |
| 17 | + |
| 18 | + ```ts |
| 19 | + import { MemoryQueueAdapter, Queue } from "@vorsteh-queue/core" |
| 20 | + |
| 21 | + type EmailPayload = { to: string; body: string } |
| 22 | + type EmailResult = { ok: boolean } |
| 23 | + |
| 24 | + const adapter = new MemoryQueueAdapter() |
| 25 | + const queue = new Queue<EmailPayload, EmailResult>(adapter, { |
| 26 | + name: "batch-demo", |
| 27 | + batch: { minSize: 5, maxSize: 20, waitFor: 1000 }, |
| 28 | + }) |
| 29 | + |
| 30 | + queue.registerBatch("send-emails", async (jobs) => { |
| 31 | + // jobs is an array of up to 20 jobs |
| 32 | + await sendBulkEmails(jobs.map((j) => j.payload)) |
| 33 | + return jobs.map(() => ({ ok: true })) |
| 34 | + }) |
| 35 | + |
| 36 | + // Add jobs as usual |
| 37 | + await queue.addJobs("send-emails", [ |
| 38 | + { to: "a@example.com", body: "Hi A" }, |
| 39 | + { to: "b@example.com", body: "Hi B" }, |
| 40 | + // ... |
| 41 | + ]) |
| 42 | + |
| 43 | + queue.start() |
| 44 | + ``` |
| 45 | + |
| 46 | +### Patch Changes |
| 47 | + |
| 48 | +- 35f7171: update dependencies |
| 49 | + |
3 | 50 | ## 0.3.2 |
4 | 51 |
|
5 | 52 | ### Patch Changes |
|
0 commit comments