@stacksjs/bun-queue 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +231 -0
  4. package/dist/batch.d.ts +18 -0
  5. package/dist/bin/cli.js +1914 -0
  6. package/dist/cleanup.d.ts +22 -0
  7. package/dist/commands/index.d.ts +6 -0
  8. package/dist/commands/script-loader.d.ts +44 -0
  9. package/dist/config.d.ts +4 -0
  10. package/dist/cron-scheduler.d.ts +37 -0
  11. package/dist/dead-letter-queue.d.ts +16 -0
  12. package/dist/dispatch.d.ts +84 -0
  13. package/dist/distributed-lock.d.ts +25 -0
  14. package/dist/events.d.ts +27 -0
  15. package/dist/failed/failed-job-manager.d.ts +17 -0
  16. package/dist/failed/failed-job-provider.d.ts +37 -0
  17. package/dist/failed/index.d.ts +7 -0
  18. package/dist/group.d.ts +22 -0
  19. package/dist/index.d.ts +72 -0
  20. package/dist/job-base.d.ts +95 -0
  21. package/dist/job-processor.d.ts +21 -0
  22. package/dist/job.d.ts +27 -0
  23. package/dist/jobs/bus.d.ts +60 -0
  24. package/dist/jobs/index.d.ts +14 -0
  25. package/dist/jobs/middleware.d.ts +37 -0
  26. package/dist/leader-election.d.ts +39 -0
  27. package/dist/logger.d.ts +14 -0
  28. package/dist/metrics.d.ts +22 -0
  29. package/dist/middleware.d.ts +61 -0
  30. package/dist/observable.d.ts +23 -0
  31. package/dist/priority-queue.d.ts +40 -0
  32. package/dist/queue-manager.d.ts +24 -0
  33. package/dist/queue.d.ts +114 -0
  34. package/dist/rate-limiter.d.ts +13 -0
  35. package/dist/src/index.js +17057 -0
  36. package/dist/stalled-checker.d.ts +14 -0
  37. package/dist/types.d.ts +180 -0
  38. package/dist/utils.d.ts +26 -0
  39. package/dist/work-coordinator.d.ts +35 -0
  40. package/dist/worker.d.ts +19 -0
  41. package/dist/workers/index.d.ts +6 -0
  42. package/dist/workers/queue-worker.d.ts +62 -0
  43. package/dist/workers/worker-manager.d.ts +22 -0
  44. package/package.json +75 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,79 @@
1
+ # Changelog
2
+
3
+ ### ๐Ÿงน Chores
4
+
5
+ - wip ([12d8d97](https://github.com/stacksjs/bun-queue/commit/12d8d97)) _(by glennmichael123 <gtorregosa@gmail.com>)_
6
+ - wip ([631b555](https://github.com/stacksjs/bun-queue/commit/631b555)) _(by glennmichael123 <gtorregosa@gmail.com>)_
7
+ - **deps**: update all non-major dependencies (#734) ([c74e4b5](https://github.com/stacksjs/bun-queue/commit/c74e4b5)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#734](https://github.com/stacksjs/bun-queue/issues/734), [#734](https://github.com/stacksjs/bun-queue/issues/734))
8
+ - **deps**: update dependency vue-tsc to 3.2.4 (#659) ([5b6a430](https://github.com/stacksjs/bun-queue/commit/5b6a430)) _(by Chris <chrisbreuer93@gmail.com>)_ ([#659](https://github.com/stacksjs/bun-queue/issues/659), [#659](https://github.com/stacksjs/bun-queue/issues/659))
9
+ - **deps**: update dependency vue-router to 5.0.2 (#658) ([eb046d9](https://github.com/stacksjs/bun-queue/commit/eb046d9)) _(by Chris <chrisbreuer93@gmail.com>)_ ([#658](https://github.com/stacksjs/bun-queue/issues/658), [#658](https://github.com/stacksjs/bun-queue/issues/658))
10
+ - **deps**: update dependency @vitejs/plugin-vue to 6.0.4 (#657) ([b3ec970](https://github.com/stacksjs/bun-queue/commit/b3ec970)) _(by Chris <chrisbreuer93@gmail.com>)_ ([#657](https://github.com/stacksjs/bun-queue/issues/657), [#657](https://github.com/stacksjs/bun-queue/issues/657))
11
+ - **deps**: update dependency vue-router to v5 (#160) ([671e779](https://github.com/stacksjs/bun-queue/commit/671e779)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#160](https://github.com/stacksjs/bun-queue/issues/160), [#160](https://github.com/stacksjs/bun-queue/issues/160))
12
+ - release v0.0.1 ([f0a90ad](https://github.com/stacksjs/bun-queue/commit/f0a90ad)) _(by glennmichael123 <gtorregosa@gmail.com>)_
13
+ - wip ([16f09fc](https://github.com/stacksjs/bun-queue/commit/16f09fc)) _(by glennmichael123 <gtorregosa@gmail.com>)_
14
+ - wip ([5a9714f](https://github.com/stacksjs/bun-queue/commit/5a9714f)) _(by glennmichael123 <gtorregosa@gmail.com>)_
15
+ - wip ([b7e5704](https://github.com/stacksjs/bun-queue/commit/b7e5704)) _(by glennmichael123 <gtorregosa@gmail.com>)_
16
+ - wip ([4ea8161](https://github.com/stacksjs/bun-queue/commit/4ea8161)) _(by glennmichael123 <gtorregosa@gmail.com>)_
17
+ - wip ([43f06ad](https://github.com/stacksjs/bun-queue/commit/43f06ad)) _(by glennmichael123 <gtorregosa@gmail.com>)_
18
+ - wip ([aa39ed1](https://github.com/stacksjs/bun-queue/commit/aa39ed1)) _(by glennmichael123 <gtorregosa@gmail.com>)_
19
+ - wip ([c7ee95d](https://github.com/stacksjs/bun-queue/commit/c7ee95d)) _(by glennmichael123 <gtorregosa@gmail.com>)_
20
+ - **deps**: update all non-major dependencies (#52) ([c067652](https://github.com/stacksjs/bun-queue/commit/c067652)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#52](https://github.com/stacksjs/bun-queue/issues/52), [#52](https://github.com/stacksjs/bun-queue/issues/52))
21
+ - **deps**: update actions/cache action to v5 (#54) ([a8c90e6](https://github.com/stacksjs/bun-queue/commit/a8c90e6)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#54](https://github.com/stacksjs/bun-queue/issues/54), [#54](https://github.com/stacksjs/bun-queue/issues/54))
22
+ - wip ([576934b](https://github.com/stacksjs/bun-queue/commit/576934b)) _(by glennmichael123 <gtorregosa@gmail.com>)_
23
+ - wip ([78ca4d2](https://github.com/stacksjs/bun-queue/commit/78ca4d2)) _(by Chris <chrisbreuer93@gmail.com>)_
24
+ - **deps**: update dependency better-dx to ^0.2.4 (#48) ([ef71ef0](https://github.com/stacksjs/bun-queue/commit/ef71ef0)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#48](https://github.com/stacksjs/bun-queue/issues/48), [#48](https://github.com/stacksjs/bun-queue/issues/48))
25
+ - **deps**: update all non-major dependencies (#45) ([20827e5](https://github.com/stacksjs/bun-queue/commit/20827e5)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#45](https://github.com/stacksjs/bun-queue/issues/45), [#45](https://github.com/stacksjs/bun-queue/issues/45))
26
+ - **deps**: update actions/checkout action to v6 (#47) ([3e33ee7](https://github.com/stacksjs/bun-queue/commit/3e33ee7)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#47](https://github.com/stacksjs/bun-queue/issues/47), [#47](https://github.com/stacksjs/bun-queue/issues/47))
27
+ - **deps**: update dependency @unocss/reset to ^66.5.7 (#43) ([f1cb263](https://github.com/stacksjs/bun-queue/commit/f1cb263)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#43](https://github.com/stacksjs/bun-queue/issues/43), [#43](https://github.com/stacksjs/bun-queue/issues/43))
28
+ - **deps**: update all non-major dependencies (#39) ([4cb63d4](https://github.com/stacksjs/bun-queue/commit/4cb63d4)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#39](https://github.com/stacksjs/bun-queue/issues/39), [#39](https://github.com/stacksjs/bun-queue/issues/39))
29
+ - wip ([43e4085](https://github.com/stacksjs/bun-queue/commit/43e4085)) _(by glennmichael123 <gtorregosa@gmail.com>)_
30
+ - wip ([e705718](https://github.com/stacksjs/bun-queue/commit/e705718)) _(by glennmichael123 <gtorregosa@gmail.com>)_
31
+ - wip ([5149131](https://github.com/stacksjs/bun-queue/commit/5149131)) _(by glennmichael123 <gtorregosa@gmail.com>)_
32
+ - wip ([9bb6946](https://github.com/stacksjs/bun-queue/commit/9bb6946)) _(by glennmichael123 <gtorregosa@gmail.com>)_
33
+ - **deps**: update dependency vite to v7 (#11) ([c59e0a5](https://github.com/stacksjs/bun-queue/commit/c59e0a5)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#11](https://github.com/stacksjs/bun-queue/issues/11), [#11](https://github.com/stacksjs/bun-queue/issues/11))
34
+ - **deps**: update actions/checkout action to v5 (#13) ([8ba17bf](https://github.com/stacksjs/bun-queue/commit/8ba17bf)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#13](https://github.com/stacksjs/bun-queue/issues/13), [#13](https://github.com/stacksjs/bun-queue/issues/13))
35
+ - **deps**: update all non-major dependencies (#7) ([227bd13](https://github.com/stacksjs/bun-queue/commit/227bd13)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#7](https://github.com/stacksjs/bun-queue/issues/7), [#7](https://github.com/stacksjs/bun-queue/issues/7))
36
+ - wip ([72b5318](https://github.com/stacksjs/bun-queue/commit/72b5318)) _(by Chris <chrisbreuer93@gmail.com>)_
37
+ - wip ([0076af6](https://github.com/stacksjs/bun-queue/commit/0076af6)) _(by Chris <chrisbreuer93@gmail.com>)_
38
+ - wip ([29b76eb](https://github.com/stacksjs/bun-queue/commit/29b76eb)) _(by Chris <chrisbreuer93@gmail.com>)_
39
+ - wip ([d540271](https://github.com/stacksjs/bun-queue/commit/d540271)) _(by Chris <chrisbreuer93@gmail.com>)_
40
+ - wip ([065aeb8](https://github.com/stacksjs/bun-queue/commit/065aeb8)) _(by Chris <chrisbreuer93@gmail.com>)_
41
+ - wip ([5b41099](https://github.com/stacksjs/bun-queue/commit/5b41099)) _(by Chris <chrisbreuer93@gmail.com>)_
42
+ - update tools ([ae152b7](https://github.com/stacksjs/bun-queue/commit/ae152b7)) _(by Adelino Ngomacha <adelinob335@gmail.com>)_
43
+ - update tools ([520c4f3](https://github.com/stacksjs/bun-queue/commit/520c4f3)) _(by Adelino Ngomacha <adelinob335@gmail.com>)_
44
+ - **deps**: update all non-major dependencies (#3) ([e6c1351](https://github.com/stacksjs/bun-queue/commit/e6c1351)) _(by [renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot]))_ ([#3](https://github.com/stacksjs/bun-queue/issues/3), [#3](https://github.com/stacksjs/bun-queue/issues/3))
45
+ - wip ([cc596ba](https://github.com/stacksjs/bun-queue/commit/cc596ba)) _(by Chris <chrisbreuer93@gmail.com>)_
46
+ - wip ([8eb1ef1](https://github.com/stacksjs/bun-queue/commit/8eb1ef1)) _(by Chris <chrisbreuer93@gmail.com>)_
47
+ - wip ([78f4766](https://github.com/stacksjs/bun-queue/commit/78f4766)) _(by Chris <chrisbreuer93@gmail.com>)_
48
+ - wip ([5789ce9](https://github.com/stacksjs/bun-queue/commit/5789ce9)) _(by Chris <chrisbreuer93@gmail.com>)_
49
+ - wip ([b83f35c](https://github.com/stacksjs/bun-queue/commit/b83f35c)) _(by Chris <chrisbreuer93@gmail.com>)_
50
+ - wip ([fc5b287](https://github.com/stacksjs/bun-queue/commit/fc5b287)) _(by Chris <chrisbreuer93@gmail.com>)_
51
+ - wip ([4fbdf26](https://github.com/stacksjs/bun-queue/commit/4fbdf26)) _(by Chris <chrisbreuer93@gmail.com>)_
52
+ - wip ([64cf43d](https://github.com/stacksjs/bun-queue/commit/64cf43d)) _(by Chris <chrisbreuer93@gmail.com>)_
53
+ - wip ([18c680e](https://github.com/stacksjs/bun-queue/commit/18c680e)) _(by Chris <chrisbreuer93@gmail.com>)_
54
+ - wip ([71fddf7](https://github.com/stacksjs/bun-queue/commit/71fddf7)) _(by Chris <chrisbreuer93@gmail.com>)_
55
+ - wip ([ab2cb74](https://github.com/stacksjs/bun-queue/commit/ab2cb74)) _(by Chris <chrisbreuer93@gmail.com>)_
56
+ - wip ([82554ed](https://github.com/stacksjs/bun-queue/commit/82554ed)) _(by Chris <chrisbreuer93@gmail.com>)_
57
+ - wip ([a948214](https://github.com/stacksjs/bun-queue/commit/a948214)) _(by Chris <chrisbreuer93@gmail.com>)_
58
+ - wip ([090bbb9](https://github.com/stacksjs/bun-queue/commit/090bbb9)) _(by Chris <chrisbreuer93@gmail.com>)_
59
+ - wip ([660c1a5](https://github.com/stacksjs/bun-queue/commit/660c1a5)) _(by Chris <chrisbreuer93@gmail.com>)_
60
+ - wip ([1b4e662](https://github.com/stacksjs/bun-queue/commit/1b4e662)) _(by Chris <chrisbreuer93@gmail.com>)_
61
+ - wip ([f995e02](https://github.com/stacksjs/bun-queue/commit/f995e02)) _(by Chris <chrisbreuer93@gmail.com>)_
62
+ - wip ([eb19ddf](https://github.com/stacksjs/bun-queue/commit/eb19ddf)) _(by Chris <chrisbreuer93@gmail.com>)_
63
+ - wip ([527b0b8](https://github.com/stacksjs/bun-queue/commit/527b0b8)) _(by Chris <chrisbreuer93@gmail.com>)_
64
+ - wip ([850509a](https://github.com/stacksjs/bun-queue/commit/850509a)) _(by Chris <chrisbreuer93@gmail.com>)_
65
+ - wip ([bef9330](https://github.com/stacksjs/bun-queue/commit/bef9330)) _(by Chris <chrisbreuer93@gmail.com>)_
66
+ - wip ([fe8763d](https://github.com/stacksjs/bun-queue/commit/fe8763d)) _(by Chris <chrisbreuer93@gmail.com>)_
67
+ - wip ([797f589](https://github.com/stacksjs/bun-queue/commit/797f589)) _(by Chris <chrisbreuer93@gmail.com>)_
68
+ - initial commit ([0667d7d](https://github.com/stacksjs/bun-queue/commit/0667d7d)) _(by Chris <chrisbreuer93@gmail.com>)_
69
+
70
+ ### ๐Ÿ“„ Miscellaneous
71
+
72
+ - Update release.yml ([f84baf9](https://github.com/stacksjs/bun-queue/commit/f84baf9)) _(by glennmichael123 <gtorregosa@gmail.com>)_
73
+
74
+ ### Contributors
75
+
76
+ - _Adelino Ngomacha <adelinob335@gmail.com>_
77
+ - _Chris <chrisbreuer93@gmail.com>_
78
+ - _[renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>](https://github.com/renovate[bot])_
79
+ - _glennmichael123 <gtorregosa@gmail.com>_
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2024 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ <p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![GitHub Actions][github-actions-src]][github-actions-href]
5
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
6
+ <!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
7
+ <!-- [![Codecov][codecov-src]][codecov-href] -->
8
+
9
+ # bun-queue
10
+
11
+ A Redis-backed job queue built for Bun, inspired by Laravel's Queue system and BullMQ.
12
+
13
+ ## Features
14
+
15
+ - Fast and efficient Redis-backed queue system
16
+ - Support for delayed jobs, retries, and prioritization
17
+ - Rate limiting capabilities
18
+ - Job event tracking
19
+ - Reliable job processing with concurrency control
20
+ - Typesafe API
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ bun add bun-queue
26
+ ```
27
+
28
+ ## Basic Usage
29
+
30
+ ```typescript
31
+ import { Queue } from 'bun-queue'
32
+
33
+ // Create a queue
34
+ const emailQueue = new Queue('emails')
35
+
36
+ // Add a job to the queue
37
+ const job = await emailQueue.add({
38
+ to: 'user@example.com',
39
+ subject: 'Welcome',
40
+ body: 'Welcome to our platform!'
41
+ })
42
+
43
+ console.log(`Job ${job.id} added to the queue`)
44
+
45
+ // Process jobs
46
+ emailQueue.process(5, async (job) => {
47
+ const { to, subject, body } = job.data
48
+
49
+ // Update progress
50
+ await job.updateProgress(10)
51
+
52
+ // Simulate sending email
53
+ console.log(`Sending email to ${to} with subject: ${subject}`)
54
+ await new Promise(resolve => setTimeout(resolve, 1000))
55
+
56
+ await job.updateProgress(100)
57
+
58
+ return { sent: true, timestamp: Date.now() }
59
+ })
60
+ ```
61
+
62
+ ## Job Options
63
+
64
+ ```typescript
65
+ // Add a job with options
66
+ await queue.add(
67
+ { task: 'process-pdf', url: 'https://example.com/document.pdf' },
68
+ {
69
+ delay: 5000, // delay for 5 seconds
70
+ attempts: 3, // retry up to 3 times
71
+ backoff: {
72
+ type: 'exponential', // 'fixed' or 'exponential'
73
+ delay: 1000, // milliseconds
74
+ },
75
+ priority: 10, // higher number = higher priority
76
+ removeOnComplete: true, // remove job when completed
77
+ lifo: false, // process in FIFO order (default)
78
+ jobId: 'custom-id', // provide custom job ID
79
+ }
80
+ )
81
+ ```
82
+
83
+ ## Delayed Jobs
84
+
85
+ ```typescript
86
+ // Add a job that will be processed after 30 seconds
87
+ await queue.add(
88
+ { task: 'send-reminder' },
89
+ { delay: 30000 }
90
+ )
91
+ ```
92
+
93
+ ## Job Management
94
+
95
+ ```typescript
96
+ // Get a job by ID
97
+ const job = await queue.getJob('job-id')
98
+
99
+ // Get jobs by status
100
+ const waitingJobs = await queue.getJobs('waiting')
101
+ const activeJobs = await queue.getJobs('active')
102
+ const completedJobs = await queue.getJobs('completed')
103
+ const failedJobs = await queue.getJobs('failed')
104
+
105
+ // Get job counts
106
+ const counts = await queue.getJobCounts()
107
+ console.log(counts) // { waiting: 5, active: 2, completed: 10, failed: 1, delayed: 3, paused: 0 }
108
+
109
+ // Pause a queue
110
+ await queue.pause()
111
+
112
+ // Resume a queue
113
+ await queue.resume()
114
+
115
+ // Retry a failed job
116
+ const failedJob = await queue.getJob('failed-job-id')
117
+ await failedJob.retry()
118
+
119
+ // Remove a job
120
+ await job.remove()
121
+
122
+ // Clear all jobs
123
+ await queue.empty()
124
+ ```
125
+
126
+ ## Rate Limiting
127
+
128
+ ```typescript
129
+ import { Queue, RateLimiter } from 'bun-queue'
130
+
131
+ const queue = new Queue('api-calls')
132
+
133
+ // Create a rate limiter (100 jobs per minute)
134
+ const limiter = new RateLimiter(queue, {
135
+ max: 100,
136
+ duration: 60000
137
+ })
138
+
139
+ // Check if rate limited before adding job
140
+ const { limited, remaining, resetIn } = await limiter.check()
141
+
142
+ if (!limited) {
143
+ await queue.add({ url: 'https://api.example.com/endpoint' })
144
+ console.log(`Job added. ${remaining} requests remaining.`)
145
+ }
146
+ else {
147
+ console.log(`Rate limited. Try again in ${resetIn}ms.`)
148
+ }
149
+ ```
150
+
151
+ ## Configuration
152
+
153
+ ```typescript
154
+ import { Queue } from 'bun-queue'
155
+
156
+ // Configure queue with options
157
+ const queue = new Queue('tasks', {
158
+ redis: {
159
+ url: 'redis://username:password@localhost:6379'
160
+ // Or provide your own client
161
+ // client: myRedisClient
162
+ },
163
+ prefix: 'myapp', // prefix for Redis keys (default: 'queue')
164
+ defaultJobOptions: {
165
+ attempts: 5,
166
+ backoff: {
167
+ type: 'exponential',
168
+ delay: 5000
169
+ }
170
+ }
171
+ })
172
+ ```
173
+
174
+ ## Environment Variables
175
+
176
+ The library reads these environment variables (in order of precedence):
177
+
178
+ - `REDIS_URL`: Redis connection string
179
+ - Default is `redis://localhost:6379` if not set
180
+
181
+ ## Testing
182
+
183
+ ```bash
184
+ bun test
185
+ ```
186
+
187
+ ## Changelog
188
+
189
+ Please see our [releases](https://github.com/stackjs/bun-queue/releases) page for more information on what has changed recently.
190
+
191
+ ## Contributing
192
+
193
+ Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
194
+
195
+ ## Community
196
+
197
+ For help, discussion about best practices, or any other conversation that would benefit from being searchable:
198
+
199
+ [Discussions on GitHub](https://github.com/stacksjs/bun-queue/discussions)
200
+
201
+ For casual chit-chat with others using this package:
202
+
203
+ [Join the Stacks Discord Server](https://discord.gg/stacksjs)
204
+
205
+ ## Postcardware
206
+
207
+ "Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.
208
+
209
+ Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐ŸŒŽ
210
+
211
+ ## Sponsors
212
+
213
+ We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
214
+
215
+ - [JetBrains](https://www.jetbrains.com/)
216
+ - [The Solana Foundation](https://solana.com/)
217
+
218
+ ## License
219
+
220
+ The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
221
+
222
+ Made with ๐Ÿ’™
223
+
224
+ <!-- Badges -->
225
+ [npm-version-src]: https://img.shields.io/npm/v/bun-queue?style=flat-square
226
+ [npm-version-href]: https://npmjs.com/package/bun-queue
227
+ [github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/bun-queue/ci.yml?style=flat-square&branch=main
228
+ [github-actions-href]: https://github.com/stacksjs/bun-queue/actions?query=workflow%3Aci
229
+
230
+ <!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/bun-queue/main?style=flat-square
231
+ [codecov-href]: https://codecov.io/gh/stacksjs/bun-queue -->
@@ -0,0 +1,18 @@
1
+ import type { RedisClient } from 'bun';
2
+ import type { Batch, BatchOptions, Job } from './types';
3
+ import type { Queue } from './queue';
4
+ export declare class BatchProcessor<T = any> {
5
+ readonly private queue: Queue<T>;
6
+ readonly private redisClient: RedisClient;
7
+ readonly private keyPrefix: string;
8
+ readonly private logger: any;
9
+ constructor(queue: Queue<T>);
10
+ createBatch(jobs: T[], options?: BatchOptions): Promise<Batch<T>>;
11
+ processBatch<R = any>(batchId: string, handler: (jobs: Job<T>[]) => Promise<R[]>): Promise<R[]>;
12
+ getBatchJobs(batchId: string): Promise<Job<T>[]>;
13
+ getBatch(batchId: string): Promise<Batch<T> | null>;
14
+ setBatchProgress(batchId: string, progress: number): Promise<void>;
15
+ removeBatch(batchId: string): Promise<void>;
16
+ private getBatchKey(batchId: string): string;
17
+ private getBatchJobsKey(batchId: string): string;
18
+ }