@hazeljs/queue 0.2.0-alpha.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.
- package/LICENSE +192 -0
- package/README.md +175 -0
- package/dist/__tests__/queue.decorator.test.d.ts +2 -0
- package/dist/__tests__/queue.decorator.test.d.ts.map +1 -0
- package/dist/__tests__/queue.decorator.test.js +127 -0
- package/dist/__tests__/queue.module.test.d.ts +2 -0
- package/dist/__tests__/queue.module.test.d.ts.map +1 -0
- package/dist/__tests__/queue.module.test.js +94 -0
- package/dist/__tests__/queue.service.test.d.ts +2 -0
- package/dist/__tests__/queue.service.test.d.ts.map +1 -0
- package/dist/__tests__/queue.service.test.js +101 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/queue.decorator.d.ts +30 -0
- package/dist/queue.decorator.d.ts.map +1 -0
- package/dist/queue.decorator.js +36 -0
- package/dist/queue.module.d.ts +61 -0
- package/dist/queue.module.d.ts.map +1 -0
- package/dist/queue.module.js +87 -0
- package/dist/queue.service.d.ts +57 -0
- package/dist/queue.service.d.ts.map +1 -0
- package/dist/queue.service.js +96 -0
- package/dist/queue.types.d.ts +46 -0
- package/dist/queue.types.d.ts.map +1 -0
- package/dist/queue.types.js +5 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024 HazelJS Team
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @hazeljs/queue
|
|
2
|
+
|
|
3
|
+
**Background jobs that don't get lost.**
|
|
4
|
+
|
|
5
|
+
BullMQ + Redis. Add jobs from controllers, process with `@Queue`. Delay, retry, priority, backoff. Works with CronModule for distributed cron. Agent tasks, emails, exports — queue it and forget it.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@hazeljs/queue)
|
|
8
|
+
[](https://www.npmjs.com/package/@hazeljs/queue)
|
|
9
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Redis-backed** - Uses BullMQ for reliable, distributed job queues
|
|
14
|
+
- **QueueService** - Injectable service for adding jobs from controllers and services
|
|
15
|
+
- **@Queue decorator** - Mark methods as job processors for Worker setup
|
|
16
|
+
- **Job options** - Delay, priority, attempts, backoff, timeout
|
|
17
|
+
- **HazelJS integration** - Works with CronModule for distributed cron jobs
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @hazeljs/queue ioredis
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### 1. Import QueueModule
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { HazelModule } from '@hazeljs/core';
|
|
31
|
+
import { QueueModule } from '@hazeljs/queue';
|
|
32
|
+
|
|
33
|
+
@HazelModule({
|
|
34
|
+
imports: [
|
|
35
|
+
QueueModule.forRoot({
|
|
36
|
+
connection: {
|
|
37
|
+
host: process.env.REDIS_HOST || 'localhost',
|
|
38
|
+
port: parseInt(process.env.REDIS_PORT || '6379', 10),
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
export class AppModule {}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Add Jobs
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Injectable } from '@hazeljs/core';
|
|
50
|
+
import { QueueService } from '@hazeljs/queue';
|
|
51
|
+
|
|
52
|
+
@Injectable()
|
|
53
|
+
export class EmailService {
|
|
54
|
+
constructor(private queue: QueueService) {}
|
|
55
|
+
|
|
56
|
+
async sendWelcomeEmail(userId: string, email: string) {
|
|
57
|
+
await this.queue.add('emails', 'welcome', { userId, email });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async sendDelayedReminder(userId: string, delayMs: number) {
|
|
61
|
+
await this.queue.addDelayed('emails', 'reminder', { userId }, delayMs);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async processWithRetry(data: { orderId: string }) {
|
|
65
|
+
await this.queue.addWithRetry('orders', 'process', data, {
|
|
66
|
+
attempts: 3,
|
|
67
|
+
backoff: { type: 'exponential', delay: 1000 },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. Process Jobs with BullMQ Worker
|
|
74
|
+
|
|
75
|
+
Create a worker process (or run alongside your app) to process jobs:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { Worker } from 'bullmq';
|
|
79
|
+
|
|
80
|
+
const worker = new Worker(
|
|
81
|
+
'emails',
|
|
82
|
+
async (job) => {
|
|
83
|
+
if (job.name === 'welcome') {
|
|
84
|
+
await sendWelcomeEmail(job.data.userId, job.data.email);
|
|
85
|
+
} else if (job.name === 'reminder') {
|
|
86
|
+
await sendReminder(job.data.userId);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
connection: {
|
|
91
|
+
host: process.env.REDIS_HOST || 'localhost',
|
|
92
|
+
port: parseInt(process.env.REDIS_PORT || '6379', 10),
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
worker.on('completed', (job) => console.log(`Job ${job.id} completed`));
|
|
98
|
+
worker.on('failed', (job, err) => console.error(`Job ${job?.id} failed:`, err));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 4. Using @Queue Decorator for Processor Metadata
|
|
102
|
+
|
|
103
|
+
The `@Queue` decorator marks methods as job processors. Use `QueueModule.getProcessorMetadata()` to get processor info for Worker setup:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Injectable } from '@hazeljs/core';
|
|
107
|
+
import { Queue } from '@hazeljs/queue';
|
|
108
|
+
|
|
109
|
+
@Injectable()
|
|
110
|
+
export class EmailProcessor {
|
|
111
|
+
@Queue('emails')
|
|
112
|
+
async handleWelcome(job: { data: { userId: string; email: string } }) {
|
|
113
|
+
await this.sendWelcome(job.data.userId, job.data.email);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Queue('emails')
|
|
117
|
+
async handleReminder(job: { data: { userId: string } }) {
|
|
118
|
+
await this.sendReminder(job.data.userId);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async sendWelcome(userId: string, email: string) {
|
|
122
|
+
// ...
|
|
123
|
+
}
|
|
124
|
+
private async sendReminder(userId: string) {
|
|
125
|
+
// ...
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Integration with Cron
|
|
131
|
+
|
|
132
|
+
For distributed cron jobs, enqueue work from cron handlers instead of doing it inline:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { Injectable } from '@hazeljs/core';
|
|
136
|
+
import { Cron, CronExpression } from '@hazeljs/cron';
|
|
137
|
+
import { QueueService } from '@hazeljs/queue';
|
|
138
|
+
|
|
139
|
+
@Injectable()
|
|
140
|
+
export class TaskService {
|
|
141
|
+
constructor(private queue: QueueService) {}
|
|
142
|
+
|
|
143
|
+
@Cron({
|
|
144
|
+
name: 'daily-cleanup',
|
|
145
|
+
cronTime: CronExpression.EVERY_DAY_AT_MIDNIGHT,
|
|
146
|
+
})
|
|
147
|
+
async triggerCleanup() {
|
|
148
|
+
// Enqueue for distributed processing instead of running inline
|
|
149
|
+
await this.queue.add('maintenance', 'daily-cleanup', {});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### QueueService
|
|
157
|
+
|
|
158
|
+
- `add(queueName, jobName, data?, options?)` - Add a job
|
|
159
|
+
- `addDelayed(queueName, jobName, data, delayMs)` - Add a delayed job
|
|
160
|
+
- `addWithRetry(queueName, jobName, data, options)` - Add with retry config
|
|
161
|
+
- `getQueue(name)` - Get BullMQ Queue instance
|
|
162
|
+
- `close()` - Close all queue connections
|
|
163
|
+
|
|
164
|
+
### Job Options (JobsOptions)
|
|
165
|
+
|
|
166
|
+
- `delay` - Delay before processing (ms)
|
|
167
|
+
- `priority` - Higher = processed first
|
|
168
|
+
- `attempts` - Retry count
|
|
169
|
+
- `backoff` - `{ type: 'fixed' | 'exponential', delay: number }`
|
|
170
|
+
- `timeout` - Job timeout (ms)
|
|
171
|
+
|
|
172
|
+
## See Also
|
|
173
|
+
|
|
174
|
+
- [Cron Jobs Guide](../../docs/guides/cron-jobs.md) - Schedule jobs that enqueue to Queue
|
|
175
|
+
- [BullMQ Documentation](https://docs.bullmq.io/) - Underlying queue library
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.decorator.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/queue.decorator.test.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const queue_decorator_1 = require("../queue.decorator");
|
|
14
|
+
describe('Queue decorator', () => {
|
|
15
|
+
describe('@Queue', () => {
|
|
16
|
+
it('should attach metadata to a method', () => {
|
|
17
|
+
class TestProcessor {
|
|
18
|
+
handleJob() { }
|
|
19
|
+
}
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, queue_decorator_1.Queue)('test-queue'),
|
|
22
|
+
__metadata("design:type", Function),
|
|
23
|
+
__metadata("design:paramtypes", []),
|
|
24
|
+
__metadata("design:returntype", void 0)
|
|
25
|
+
], TestProcessor.prototype, "handleJob", null);
|
|
26
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(new TestProcessor());
|
|
27
|
+
expect(metadata).toHaveLength(1);
|
|
28
|
+
expect(metadata[0].queueName).toBe('test-queue');
|
|
29
|
+
expect(metadata[0].methodName).toBe('handleJob');
|
|
30
|
+
expect(metadata[0].options).toEqual({});
|
|
31
|
+
});
|
|
32
|
+
it('should attach metadata with options', () => {
|
|
33
|
+
class TestProcessor {
|
|
34
|
+
handleWelcome() { }
|
|
35
|
+
}
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, queue_decorator_1.Queue)('emails', { name: 'welcome-handler' }),
|
|
38
|
+
__metadata("design:type", Function),
|
|
39
|
+
__metadata("design:paramtypes", []),
|
|
40
|
+
__metadata("design:returntype", void 0)
|
|
41
|
+
], TestProcessor.prototype, "handleWelcome", null);
|
|
42
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(new TestProcessor());
|
|
43
|
+
expect(metadata).toHaveLength(1);
|
|
44
|
+
expect(metadata[0].queueName).toBe('emails');
|
|
45
|
+
expect(metadata[0].options).toEqual({ name: 'welcome-handler' });
|
|
46
|
+
});
|
|
47
|
+
it('should support multiple processors on the same class', () => {
|
|
48
|
+
class MultiQueueProcessor {
|
|
49
|
+
handleEmail() { }
|
|
50
|
+
handleOrder() { }
|
|
51
|
+
handleNotification() { }
|
|
52
|
+
}
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, queue_decorator_1.Queue)('emails'),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", []),
|
|
57
|
+
__metadata("design:returntype", void 0)
|
|
58
|
+
], MultiQueueProcessor.prototype, "handleEmail", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, queue_decorator_1.Queue)('orders'),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", []),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], MultiQueueProcessor.prototype, "handleOrder", null);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, queue_decorator_1.Queue)('notifications'),
|
|
67
|
+
__metadata("design:type", Function),
|
|
68
|
+
__metadata("design:paramtypes", []),
|
|
69
|
+
__metadata("design:returntype", void 0)
|
|
70
|
+
], MultiQueueProcessor.prototype, "handleNotification", null);
|
|
71
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(new MultiQueueProcessor());
|
|
72
|
+
expect(metadata).toHaveLength(3);
|
|
73
|
+
const queueNames = metadata.map((m) => m.queueName);
|
|
74
|
+
expect(queueNames).toContain('emails');
|
|
75
|
+
expect(queueNames).toContain('orders');
|
|
76
|
+
expect(queueNames).toContain('notifications');
|
|
77
|
+
const methodNames = metadata.map((m) => m.methodName);
|
|
78
|
+
expect(methodNames).toContain('handleEmail');
|
|
79
|
+
expect(methodNames).toContain('handleOrder');
|
|
80
|
+
expect(methodNames).toContain('handleNotification');
|
|
81
|
+
});
|
|
82
|
+
it('should support multiple methods for the same queue', () => {
|
|
83
|
+
class SameQueueProcessor {
|
|
84
|
+
handleWelcome() { }
|
|
85
|
+
handleReminder() { }
|
|
86
|
+
}
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, queue_decorator_1.Queue)('emails'),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", []),
|
|
91
|
+
__metadata("design:returntype", void 0)
|
|
92
|
+
], SameQueueProcessor.prototype, "handleWelcome", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, queue_decorator_1.Queue)('emails'),
|
|
95
|
+
__metadata("design:type", Function),
|
|
96
|
+
__metadata("design:paramtypes", []),
|
|
97
|
+
__metadata("design:returntype", void 0)
|
|
98
|
+
], SameQueueProcessor.prototype, "handleReminder", null);
|
|
99
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(new SameQueueProcessor());
|
|
100
|
+
expect(metadata).toHaveLength(2);
|
|
101
|
+
expect(metadata.every((m) => m.queueName === 'emails')).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('getQueueProcessorMetadata', () => {
|
|
105
|
+
it('should return empty array for class without @Queue decorators', () => {
|
|
106
|
+
class PlainClass {
|
|
107
|
+
plainMethod() { }
|
|
108
|
+
}
|
|
109
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(new PlainClass());
|
|
110
|
+
expect(metadata).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
it('should preserve target reference in metadata', () => {
|
|
113
|
+
class ProcessorWithTarget {
|
|
114
|
+
handle() { }
|
|
115
|
+
}
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, queue_decorator_1.Queue)('test'),
|
|
118
|
+
__metadata("design:type", Function),
|
|
119
|
+
__metadata("design:paramtypes", []),
|
|
120
|
+
__metadata("design:returntype", void 0)
|
|
121
|
+
], ProcessorWithTarget.prototype, "handle", null);
|
|
122
|
+
const instance = new ProcessorWithTarget();
|
|
123
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(instance);
|
|
124
|
+
expect(metadata[0].target).toBeDefined();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.module.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/queue.module.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const core_1 = require("@hazeljs/core");
|
|
13
|
+
const queue_decorator_1 = require("../queue.decorator");
|
|
14
|
+
const queue_module_1 = require("../queue.module");
|
|
15
|
+
const queue_service_1 = require("../queue.service");
|
|
16
|
+
// Mock bullmq
|
|
17
|
+
jest.mock('bullmq', () => ({
|
|
18
|
+
Queue: jest.fn().mockImplementation(() => ({
|
|
19
|
+
add: jest.fn().mockResolvedValue({ id: 'job-1' }),
|
|
20
|
+
close: jest.fn().mockResolvedValue(undefined),
|
|
21
|
+
})),
|
|
22
|
+
}));
|
|
23
|
+
describe('QueueModule', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
core_1.Container.getInstance().clear?.();
|
|
26
|
+
});
|
|
27
|
+
describe('forRoot', () => {
|
|
28
|
+
it('should return module config with providers and exports', () => {
|
|
29
|
+
const config = queue_module_1.QueueModule.forRoot({
|
|
30
|
+
connection: { host: 'localhost', port: 6379 },
|
|
31
|
+
});
|
|
32
|
+
expect(config.module).toBe(queue_module_1.QueueModule);
|
|
33
|
+
expect(config.providers).toHaveLength(1);
|
|
34
|
+
expect(config.providers[0].provide).toBe(queue_service_1.QueueService);
|
|
35
|
+
expect(config.providers[0].useFactory).toBeDefined();
|
|
36
|
+
expect(config.exports).toContain(queue_service_1.QueueService);
|
|
37
|
+
expect(config.global).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
it('should use isGlobal option', () => {
|
|
40
|
+
const config = queue_module_1.QueueModule.forRoot({
|
|
41
|
+
connection: { host: 'localhost' },
|
|
42
|
+
isGlobal: false,
|
|
43
|
+
});
|
|
44
|
+
expect(config.global).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
it('should create QueueService with connection when useFactory is called', () => {
|
|
47
|
+
const config = queue_module_1.QueueModule.forRoot({
|
|
48
|
+
connection: { host: 'redis.example.com', port: 6380 },
|
|
49
|
+
});
|
|
50
|
+
const factory = config.providers[0].useFactory;
|
|
51
|
+
const service = factory();
|
|
52
|
+
expect(service).toBeInstanceOf(queue_service_1.QueueService);
|
|
53
|
+
// Service should be usable (connection was set)
|
|
54
|
+
expect(() => service.getQueue('test')).not.toThrow();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('getProcessorMetadata', () => {
|
|
58
|
+
it('should return empty array for object without @Queue decorators', () => {
|
|
59
|
+
const metadata = queue_module_1.QueueModule.getProcessorMetadata({ foo: 'bar' });
|
|
60
|
+
expect(metadata).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
it('should return processor metadata for class with @Queue decorators', () => {
|
|
63
|
+
class TestProcessor {
|
|
64
|
+
handleEmail() { }
|
|
65
|
+
}
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, queue_decorator_1.Queue)('emails'),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", []),
|
|
70
|
+
__metadata("design:returntype", void 0)
|
|
71
|
+
], TestProcessor.prototype, "handleEmail", null);
|
|
72
|
+
const instance = new TestProcessor();
|
|
73
|
+
const metadata = queue_module_1.QueueModule.getProcessorMetadata(instance);
|
|
74
|
+
expect(metadata).toHaveLength(1);
|
|
75
|
+
expect(metadata[0].queueName).toBe('emails');
|
|
76
|
+
expect(metadata[0].methodName).toBe('handleEmail');
|
|
77
|
+
expect(metadata[0].options).toEqual({});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe('getQueueService', () => {
|
|
81
|
+
it('should throw when QueueService is not in container', () => {
|
|
82
|
+
// Register undefined so resolve returns undefined (container auto-resolves classes otherwise)
|
|
83
|
+
core_1.Container.getInstance().register(queue_service_1.QueueService, undefined);
|
|
84
|
+
expect(() => queue_module_1.QueueModule.getQueueService()).toThrow('QueueService not found. Ensure QueueModule is imported.');
|
|
85
|
+
});
|
|
86
|
+
it('should return QueueService when registered in container', () => {
|
|
87
|
+
const service = new queue_service_1.QueueService();
|
|
88
|
+
service.setConnection({ host: 'localhost' });
|
|
89
|
+
core_1.Container.getInstance().register(queue_service_1.QueueService, service);
|
|
90
|
+
const resolved = queue_module_1.QueueModule.getQueueService();
|
|
91
|
+
expect(resolved).toBe(service);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.service.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/queue.service.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const queue_service_1 = require("../queue.service");
|
|
4
|
+
// Mock bullmq
|
|
5
|
+
const mockAdd = jest.fn();
|
|
6
|
+
const mockClose = jest.fn();
|
|
7
|
+
jest.mock('bullmq', () => ({
|
|
8
|
+
Queue: jest.fn().mockImplementation(() => ({
|
|
9
|
+
add: mockAdd,
|
|
10
|
+
close: mockClose,
|
|
11
|
+
})),
|
|
12
|
+
}));
|
|
13
|
+
describe('QueueService', () => {
|
|
14
|
+
let service;
|
|
15
|
+
const connection = { host: 'localhost', port: 6379 };
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
mockAdd.mockResolvedValue({ id: 'job-123' });
|
|
19
|
+
mockClose.mockResolvedValue(undefined);
|
|
20
|
+
service = new queue_service_1.QueueService();
|
|
21
|
+
service.setConnection(connection);
|
|
22
|
+
});
|
|
23
|
+
describe('setConnection', () => {
|
|
24
|
+
it('should store connection options', () => {
|
|
25
|
+
const svc = new queue_service_1.QueueService();
|
|
26
|
+
svc.setConnection(connection);
|
|
27
|
+
expect(() => svc.getQueue('test')).not.toThrow();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('getQueue', () => {
|
|
31
|
+
it('should throw when connection is not configured', () => {
|
|
32
|
+
const svc = new queue_service_1.QueueService();
|
|
33
|
+
expect(() => svc.getQueue('test')).toThrow('QueueService not configured. Call setConnection() or use QueueModule.forRoot()');
|
|
34
|
+
});
|
|
35
|
+
it('should create and return a queue for the given name', () => {
|
|
36
|
+
const queue = service.getQueue('my-queue');
|
|
37
|
+
expect(queue).toBeDefined();
|
|
38
|
+
expect(queue.add).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
it('should reuse existing queue for same name', () => {
|
|
41
|
+
const queue1 = service.getQueue('reused');
|
|
42
|
+
const queue2 = service.getQueue('reused');
|
|
43
|
+
expect(queue1).toBe(queue2);
|
|
44
|
+
});
|
|
45
|
+
it('should create different queues for different names', () => {
|
|
46
|
+
const queue1 = service.getQueue('queue-a');
|
|
47
|
+
const queue2 = service.getQueue('queue-b');
|
|
48
|
+
expect(queue1).not.toBe(queue2);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('add', () => {
|
|
52
|
+
it('should add a job and return id', async () => {
|
|
53
|
+
const result = await service.add('emails', 'welcome', { userId: '1', email: 'a@b.com' });
|
|
54
|
+
expect(result).toEqual({ id: 'job-123' });
|
|
55
|
+
expect(mockAdd).toHaveBeenCalledWith('welcome', { userId: '1', email: 'a@b.com' }, undefined);
|
|
56
|
+
});
|
|
57
|
+
it('should add job with empty object when data is undefined', async () => {
|
|
58
|
+
await service.add('tasks', 'run');
|
|
59
|
+
expect(mockAdd).toHaveBeenCalledWith('run', {}, undefined);
|
|
60
|
+
});
|
|
61
|
+
it('should pass job options to BullMQ', async () => {
|
|
62
|
+
await service.add('tasks', 'process', { id: 1 }, { delay: 5000, priority: 10 });
|
|
63
|
+
expect(mockAdd).toHaveBeenCalledWith('process', { id: 1 }, {
|
|
64
|
+
delay: 5000,
|
|
65
|
+
priority: 10,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('addDelayed', () => {
|
|
70
|
+
it('should add job with delay', async () => {
|
|
71
|
+
await service.addDelayed('emails', 'reminder', { userId: '1' }, 3000);
|
|
72
|
+
expect(mockAdd).toHaveBeenCalledWith('reminder', { userId: '1' }, { delay: 3000 });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('addWithRetry', () => {
|
|
76
|
+
it('should add job with retry options', async () => {
|
|
77
|
+
await service.addWithRetry('orders', 'process', { orderId: 'o1' }, {
|
|
78
|
+
attempts: 3,
|
|
79
|
+
backoff: { type: 'exponential', delay: 1000 },
|
|
80
|
+
});
|
|
81
|
+
expect(mockAdd).toHaveBeenCalledWith('process', { orderId: 'o1' }, {
|
|
82
|
+
attempts: 3,
|
|
83
|
+
backoff: { type: 'exponential', delay: 1000 },
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('close', () => {
|
|
88
|
+
it('should close all queues', async () => {
|
|
89
|
+
service.getQueue('q1');
|
|
90
|
+
service.getQueue('q2');
|
|
91
|
+
await service.close();
|
|
92
|
+
expect(mockClose).toHaveBeenCalledTimes(2);
|
|
93
|
+
});
|
|
94
|
+
it('should clear queues map after close', async () => {
|
|
95
|
+
service.getQueue('q1');
|
|
96
|
+
await service.close();
|
|
97
|
+
// After close, getQueue would create new instance - we verify close was called
|
|
98
|
+
expect(mockClose).toHaveBeenCalled();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hazeljs/queue - Redis-backed job queue module for HazelJS using BullMQ
|
|
3
|
+
*/
|
|
4
|
+
export { QueueModule, type QueueModuleOptions } from './queue.module';
|
|
5
|
+
export { QueueService } from './queue.service';
|
|
6
|
+
export { Queue, getQueueProcessorMetadata } from './queue.decorator';
|
|
7
|
+
export type { QueueDecoratorOptions } from './queue.decorator';
|
|
8
|
+
export type { RedisConnectionOptions, QueueJobOptions, QueueProcessorMetadata, } from './queue.types';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACrE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,sBAAsB,GACvB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @hazeljs/queue - Redis-backed job queue module for HazelJS using BullMQ
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getQueueProcessorMetadata = exports.Queue = exports.QueueService = exports.QueueModule = void 0;
|
|
7
|
+
var queue_module_1 = require("./queue.module");
|
|
8
|
+
Object.defineProperty(exports, "QueueModule", { enumerable: true, get: function () { return queue_module_1.QueueModule; } });
|
|
9
|
+
var queue_service_1 = require("./queue.service");
|
|
10
|
+
Object.defineProperty(exports, "QueueService", { enumerable: true, get: function () { return queue_service_1.QueueService; } });
|
|
11
|
+
var queue_decorator_1 = require("./queue.decorator");
|
|
12
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_decorator_1.Queue; } });
|
|
13
|
+
Object.defineProperty(exports, "getQueueProcessorMetadata", { enumerable: true, get: function () { return queue_decorator_1.getQueueProcessorMetadata; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Metadata key for queue processors
|
|
4
|
+
*/
|
|
5
|
+
export declare const QUEUE_PROCESSOR_METADATA_KEY: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Options for the @Queue decorator
|
|
8
|
+
*/
|
|
9
|
+
export interface QueueDecoratorOptions {
|
|
10
|
+
/** Queue name (defaults to class.methodName) */
|
|
11
|
+
name?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Decorator to mark a method as a queue job processor
|
|
15
|
+
* The method will be invoked when jobs are processed from the named queue
|
|
16
|
+
*
|
|
17
|
+
* @param queueName - Name of the queue this processor handles
|
|
18
|
+
* @param options - Optional processor configuration
|
|
19
|
+
*/
|
|
20
|
+
export declare function Queue(queueName: string, options?: QueueDecoratorOptions): MethodDecorator;
|
|
21
|
+
/**
|
|
22
|
+
* Get queue processor metadata from a class
|
|
23
|
+
*/
|
|
24
|
+
export declare function getQueueProcessorMetadata(target: object): Array<{
|
|
25
|
+
queueName: string;
|
|
26
|
+
methodName: string;
|
|
27
|
+
target: object;
|
|
28
|
+
options: QueueDecoratorOptions;
|
|
29
|
+
}>;
|
|
30
|
+
//# sourceMappingURL=queue.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.decorator.d.ts","sourceRoot":"","sources":["../src/queue.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,eAAO,MAAM,4BAA4B,eAA6B,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,eAAe,CAczF;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,qBAAqB,CAAC;CAChC,CAAC,CAED"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QUEUE_PROCESSOR_METADATA_KEY = void 0;
|
|
4
|
+
exports.Queue = Queue;
|
|
5
|
+
exports.getQueueProcessorMetadata = getQueueProcessorMetadata;
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
/**
|
|
8
|
+
* Metadata key for queue processors
|
|
9
|
+
*/
|
|
10
|
+
exports.QUEUE_PROCESSOR_METADATA_KEY = Symbol('queue:processors');
|
|
11
|
+
/**
|
|
12
|
+
* Decorator to mark a method as a queue job processor
|
|
13
|
+
* The method will be invoked when jobs are processed from the named queue
|
|
14
|
+
*
|
|
15
|
+
* @param queueName - Name of the queue this processor handles
|
|
16
|
+
* @param options - Optional processor configuration
|
|
17
|
+
*/
|
|
18
|
+
function Queue(queueName, options) {
|
|
19
|
+
return (target, propertyKey, _descriptor) => {
|
|
20
|
+
const existing = Reflect.getMetadata(exports.QUEUE_PROCESSOR_METADATA_KEY, target.constructor) || [];
|
|
21
|
+
const metadata = {
|
|
22
|
+
queueName,
|
|
23
|
+
methodName: propertyKey.toString(),
|
|
24
|
+
target,
|
|
25
|
+
options: options || {},
|
|
26
|
+
};
|
|
27
|
+
existing.push(metadata);
|
|
28
|
+
Reflect.defineMetadata(exports.QUEUE_PROCESSOR_METADATA_KEY, existing, target.constructor);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get queue processor metadata from a class
|
|
33
|
+
*/
|
|
34
|
+
function getQueueProcessorMetadata(target) {
|
|
35
|
+
return Reflect.getMetadata(exports.QUEUE_PROCESSOR_METADATA_KEY, target.constructor) || [];
|
|
36
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { QueueService } from './queue.service';
|
|
2
|
+
import type { RedisConnectionOptions } from './queue.types';
|
|
3
|
+
/**
|
|
4
|
+
* Queue module options
|
|
5
|
+
*/
|
|
6
|
+
export interface QueueModuleOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Redis connection options for BullMQ
|
|
9
|
+
* Passed to ioredis constructor
|
|
10
|
+
*/
|
|
11
|
+
connection: RedisConnectionOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Whether this is a global module
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
isGlobal?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Queue module for HazelJS
|
|
20
|
+
* Provides Redis-backed job queues using BullMQ
|
|
21
|
+
*/
|
|
22
|
+
export declare class QueueModule {
|
|
23
|
+
/**
|
|
24
|
+
* Configure queue module with Redis connection
|
|
25
|
+
*/
|
|
26
|
+
static forRoot(options: QueueModuleOptions): {
|
|
27
|
+
module: typeof QueueModule;
|
|
28
|
+
providers: Array<{
|
|
29
|
+
provide: typeof QueueService;
|
|
30
|
+
useFactory: () => QueueService;
|
|
31
|
+
}>;
|
|
32
|
+
exports: Array<typeof QueueService>;
|
|
33
|
+
global: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Register queue processors from a provider instance
|
|
37
|
+
* Call this after the provider is instantiated and workers are ready
|
|
38
|
+
*
|
|
39
|
+
* Note: For BullMQ workers, you typically need to create Worker instances
|
|
40
|
+
* that call into your processor methods. This helper retrieves metadata
|
|
41
|
+
* for integration with worker setup.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const taskService = container.resolve(TaskService);
|
|
46
|
+
* const metadata = QueueModule.getProcessorMetadata(taskService);
|
|
47
|
+
* // Use metadata to set up BullMQ Workers
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
static getProcessorMetadata(provider: object): Array<{
|
|
51
|
+
queueName: string;
|
|
52
|
+
methodName: string;
|
|
53
|
+
options: Record<string, unknown>;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Get QueueService from the container and ensure it has connection configured
|
|
57
|
+
* Useful when using QueueModule without forRoot (e.g. manual connection setup)
|
|
58
|
+
*/
|
|
59
|
+
static getQueueService(): QueueService;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=queue.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.module.d.ts","sourceRoot":"","sources":["../src/queue.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,EAAE,sBAAsB,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,qBAIa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG;QAC3C,MAAM,EAAE,OAAO,WAAW,CAAC;QAC3B,SAAS,EAAE,KAAK,CAAC;YAAE,OAAO,EAAE,OAAO,YAAY,CAAC;YAAC,UAAU,EAAE,MAAM,YAAY,CAAA;SAAE,CAAC,CAAC;QACnF,OAAO,EAAE,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;QACpC,MAAM,EAAE,OAAO,CAAC;KACjB;IAsBD;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;QACnD,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,CAAC;IASF;;;OAGG;IACH,MAAM,CAAC,eAAe,IAAI,YAAY;CAQvC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
var QueueModule_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.QueueModule = void 0;
|
|
14
|
+
const core_1 = require("@hazeljs/core");
|
|
15
|
+
const queue_service_1 = require("./queue.service");
|
|
16
|
+
const queue_decorator_1 = require("./queue.decorator");
|
|
17
|
+
const core_2 = require("@hazeljs/core");
|
|
18
|
+
const core_3 = __importDefault(require("@hazeljs/core"));
|
|
19
|
+
/**
|
|
20
|
+
* Queue module for HazelJS
|
|
21
|
+
* Provides Redis-backed job queues using BullMQ
|
|
22
|
+
*/
|
|
23
|
+
let QueueModule = QueueModule_1 = class QueueModule {
|
|
24
|
+
/**
|
|
25
|
+
* Configure queue module with Redis connection
|
|
26
|
+
*/
|
|
27
|
+
static forRoot(options) {
|
|
28
|
+
const { connection, isGlobal = true } = options;
|
|
29
|
+
core_3.default.info('Configuring queue module with BullMQ...');
|
|
30
|
+
const queueServiceProvider = {
|
|
31
|
+
provide: queue_service_1.QueueService,
|
|
32
|
+
useFactory: () => {
|
|
33
|
+
const service = new queue_service_1.QueueService();
|
|
34
|
+
service.setConnection(connection);
|
|
35
|
+
return service;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
module: QueueModule_1,
|
|
40
|
+
providers: [queueServiceProvider],
|
|
41
|
+
exports: [queue_service_1.QueueService],
|
|
42
|
+
global: isGlobal,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register queue processors from a provider instance
|
|
47
|
+
* Call this after the provider is instantiated and workers are ready
|
|
48
|
+
*
|
|
49
|
+
* Note: For BullMQ workers, you typically need to create Worker instances
|
|
50
|
+
* that call into your processor methods. This helper retrieves metadata
|
|
51
|
+
* for integration with worker setup.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const taskService = container.resolve(TaskService);
|
|
56
|
+
* const metadata = QueueModule.getProcessorMetadata(taskService);
|
|
57
|
+
* // Use metadata to set up BullMQ Workers
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
static getProcessorMetadata(provider) {
|
|
61
|
+
const metadata = (0, queue_decorator_1.getQueueProcessorMetadata)(provider);
|
|
62
|
+
return metadata.map((m) => ({
|
|
63
|
+
queueName: m.queueName,
|
|
64
|
+
methodName: m.methodName,
|
|
65
|
+
options: m.options,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get QueueService from the container and ensure it has connection configured
|
|
70
|
+
* Useful when using QueueModule without forRoot (e.g. manual connection setup)
|
|
71
|
+
*/
|
|
72
|
+
static getQueueService() {
|
|
73
|
+
const container = core_2.Container.getInstance();
|
|
74
|
+
const service = container.resolve(queue_service_1.QueueService);
|
|
75
|
+
if (!service) {
|
|
76
|
+
throw new Error('QueueService not found. Ensure QueueModule is imported.');
|
|
77
|
+
}
|
|
78
|
+
return service;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.QueueModule = QueueModule;
|
|
82
|
+
exports.QueueModule = QueueModule = QueueModule_1 = __decorate([
|
|
83
|
+
(0, core_1.HazelModule)({
|
|
84
|
+
providers: [queue_service_1.QueueService],
|
|
85
|
+
exports: [queue_service_1.QueueService],
|
|
86
|
+
})
|
|
87
|
+
], QueueModule);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Queue as BullQueue, JobsOptions } from 'bullmq';
|
|
2
|
+
import type { RedisConnectionOptions } from './queue.types';
|
|
3
|
+
/**
|
|
4
|
+
* Queue service for adding and managing jobs
|
|
5
|
+
* Uses BullMQ for Redis-backed job queues
|
|
6
|
+
*/
|
|
7
|
+
export declare class QueueService {
|
|
8
|
+
private queues;
|
|
9
|
+
private connection;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the queue service with Redis connection options
|
|
12
|
+
* Must be called before using add() or getQueue()
|
|
13
|
+
*/
|
|
14
|
+
setConnection(connection: RedisConnectionOptions): void;
|
|
15
|
+
/**
|
|
16
|
+
* Get Redis connection options (for creating Workers that share the same connection)
|
|
17
|
+
*/
|
|
18
|
+
getConnection(): RedisConnectionOptions | null;
|
|
19
|
+
/**
|
|
20
|
+
* Get or create a BullMQ Queue instance for the given name
|
|
21
|
+
*/
|
|
22
|
+
getQueue<T = unknown>(name: string): BullQueue<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Add a job to a queue
|
|
25
|
+
*
|
|
26
|
+
* @param queueName - Name of the queue
|
|
27
|
+
* @param jobName - Job name/type
|
|
28
|
+
* @param data - Job payload
|
|
29
|
+
* @param options - Job options (delay, priority, attempts, backoff, etc.)
|
|
30
|
+
*/
|
|
31
|
+
add<T = unknown>(queueName: string, jobName: string, data?: T, options?: JobsOptions): Promise<{
|
|
32
|
+
id: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Add a job with a delay
|
|
36
|
+
*/
|
|
37
|
+
addDelayed<T = unknown>(queueName: string, jobName: string, data: T, delayMs: number): Promise<{
|
|
38
|
+
id: string | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Add a job with retry configuration
|
|
42
|
+
*/
|
|
43
|
+
addWithRetry<T = unknown>(queueName: string, jobName: string, data: T, options: {
|
|
44
|
+
attempts?: number;
|
|
45
|
+
backoff?: {
|
|
46
|
+
type: 'fixed' | 'exponential';
|
|
47
|
+
delay: number;
|
|
48
|
+
};
|
|
49
|
+
}): Promise<{
|
|
50
|
+
id: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Close all queue connections
|
|
54
|
+
*/
|
|
55
|
+
close(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=queue.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.service.d.ts","sourceRoot":"","sources":["../src/queue.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D;;;GAGG;AACH,qBACa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,UAAU,CAAuC;IAEzD;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI;IAKvD;;OAEG;IACH,aAAa,IAAI,sBAAsB,GAAG,IAAI;IAI9C;;OAEG;IACH,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAkBjD;;;;;;;OAOG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAYtC;;OAEG;IACG,UAAU,CAAC,CAAC,GAAG,OAAO,EAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAItC;;OAEG;IACG,YAAY,CAAC,CAAC,GAAG,OAAO,EAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,CAAC,EACP,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE;YAAE,IAAI,EAAE,OAAO,GAAG,aAAa,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACzF,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAItC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QueueService = void 0;
|
|
13
|
+
const core_1 = require("@hazeljs/core");
|
|
14
|
+
const bullmq_1 = require("bullmq");
|
|
15
|
+
const core_2 = __importDefault(require("@hazeljs/core"));
|
|
16
|
+
/**
|
|
17
|
+
* Queue service for adding and managing jobs
|
|
18
|
+
* Uses BullMQ for Redis-backed job queues
|
|
19
|
+
*/
|
|
20
|
+
let QueueService = class QueueService {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.queues = new Map();
|
|
23
|
+
this.connection = null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the queue service with Redis connection options
|
|
27
|
+
* Must be called before using add() or getQueue()
|
|
28
|
+
*/
|
|
29
|
+
setConnection(connection) {
|
|
30
|
+
this.connection = connection;
|
|
31
|
+
core_2.default.info('QueueService connection configured');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get Redis connection options (for creating Workers that share the same connection)
|
|
35
|
+
*/
|
|
36
|
+
getConnection() {
|
|
37
|
+
return this.connection;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get or create a BullMQ Queue instance for the given name
|
|
41
|
+
*/
|
|
42
|
+
getQueue(name) {
|
|
43
|
+
if (!this.connection) {
|
|
44
|
+
throw new Error('QueueService not configured. Call setConnection() or use QueueModule.forRoot() with connection options.');
|
|
45
|
+
}
|
|
46
|
+
let queue = this.queues.get(name);
|
|
47
|
+
if (!queue) {
|
|
48
|
+
queue = new bullmq_1.Queue(name, {
|
|
49
|
+
connection: this.connection,
|
|
50
|
+
});
|
|
51
|
+
this.queues.set(name, queue);
|
|
52
|
+
core_2.default.debug(`Queue "${name}" created`);
|
|
53
|
+
}
|
|
54
|
+
return queue;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Add a job to a queue
|
|
58
|
+
*
|
|
59
|
+
* @param queueName - Name of the queue
|
|
60
|
+
* @param jobName - Job name/type
|
|
61
|
+
* @param data - Job payload
|
|
62
|
+
* @param options - Job options (delay, priority, attempts, backoff, etc.)
|
|
63
|
+
*/
|
|
64
|
+
async add(queueName, jobName, data, options) {
|
|
65
|
+
const queue = this.getQueue(queueName);
|
|
66
|
+
// BullMQ has strict generics for job names; cast for dynamic queue/job names
|
|
67
|
+
const job = await queue.add(jobName, data ?? {}, options);
|
|
68
|
+
core_2.default.debug(`Job added to queue "${queueName}": ${jobName} (id: ${job.id})`);
|
|
69
|
+
return { id: job.id };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add a job with a delay
|
|
73
|
+
*/
|
|
74
|
+
async addDelayed(queueName, jobName, data, delayMs) {
|
|
75
|
+
return this.add(queueName, jobName, data, { delay: delayMs });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Add a job with retry configuration
|
|
79
|
+
*/
|
|
80
|
+
async addWithRetry(queueName, jobName, data, options) {
|
|
81
|
+
return this.add(queueName, jobName, data, options);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Close all queue connections
|
|
85
|
+
*/
|
|
86
|
+
async close() {
|
|
87
|
+
const closePromises = Array.from(this.queues.values()).map((q) => q.close());
|
|
88
|
+
await Promise.all(closePromises);
|
|
89
|
+
this.queues.clear();
|
|
90
|
+
core_2.default.info('QueueService: all queues closed');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.QueueService = QueueService;
|
|
94
|
+
exports.QueueService = QueueService = __decorate([
|
|
95
|
+
(0, core_1.Service)()
|
|
96
|
+
], QueueService);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queue module types
|
|
3
|
+
*/
|
|
4
|
+
import type { JobsOptions } from 'bullmq';
|
|
5
|
+
/**
|
|
6
|
+
* Redis connection options for BullMQ
|
|
7
|
+
* Passed to ioredis constructor
|
|
8
|
+
*/
|
|
9
|
+
export interface RedisConnectionOptions {
|
|
10
|
+
host?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
password?: string;
|
|
13
|
+
db?: number;
|
|
14
|
+
keyPrefix?: string;
|
|
15
|
+
maxRetriesPerRequest?: number | null;
|
|
16
|
+
enableReadyCheck?: boolean;
|
|
17
|
+
retryStrategy?: (times: number) => number | null;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for adding a job to the queue
|
|
22
|
+
*/
|
|
23
|
+
export interface QueueJobOptions extends Omit<JobsOptions, 'repeat'> {
|
|
24
|
+
/** Delay before job is processed (ms) */
|
|
25
|
+
delay?: number;
|
|
26
|
+
/** Job priority (higher = processed first) */
|
|
27
|
+
priority?: number;
|
|
28
|
+
/** Number of attempts before failing */
|
|
29
|
+
attempts?: number;
|
|
30
|
+
/** Backoff strategy: 'fixed' | 'exponential' */
|
|
31
|
+
backoff?: {
|
|
32
|
+
type: 'fixed' | 'exponential';
|
|
33
|
+
delay: number;
|
|
34
|
+
};
|
|
35
|
+
/** Job timeout (ms) */
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Queue processor metadata
|
|
40
|
+
*/
|
|
41
|
+
export interface QueueProcessorMetadata {
|
|
42
|
+
queueName: string;
|
|
43
|
+
methodName: string;
|
|
44
|
+
target: object;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=queue.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.types.d.ts","sourceRoot":"","sources":["../src/queue.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACjD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC;IAClE,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,OAAO,GAAG,aAAa,CAAC;QAC9B,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hazeljs/queue",
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
|
+
"description": "Redis-backed job queue module for HazelJS framework using BullMQ",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "jest --coverage --passWithNoTests",
|
|
13
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
14
|
+
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
15
|
+
"clean": "rm -rf dist"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"bullmq": "^5.34.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.17.50",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
|
23
|
+
"@typescript-eslint/parser": "^8.18.2",
|
|
24
|
+
"eslint": "^8.56.0",
|
|
25
|
+
"jest": "^29.7.0",
|
|
26
|
+
"ts-jest": "^29.1.2",
|
|
27
|
+
"typescript": "^5.3.3"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/hazel-js/hazeljs.git",
|
|
35
|
+
"directory": "packages/queue"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"hazeljs",
|
|
39
|
+
"queue",
|
|
40
|
+
"jobs",
|
|
41
|
+
"bullmq",
|
|
42
|
+
"redis",
|
|
43
|
+
"background-jobs"
|
|
44
|
+
],
|
|
45
|
+
"author": "Muhammad Arslan <muhammad.arslan@hazeljs.com>",
|
|
46
|
+
"license": "Apache-2.0",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://hazeljs.com",
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@hazeljs/core": ">=0.2.0-beta.0",
|
|
53
|
+
"ioredis": ">=5.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"ioredis": {
|
|
57
|
+
"optional": false,
|
|
58
|
+
"description": "Required for Redis connection. BullMQ uses ioredis for Redis connectivity."
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "cbc5ee2c12ced28fd0576faf13c5f078c1e8421e"
|
|
62
|
+
}
|