@go-mailer/vertebra 3.1.2 → 3.2.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/lib/constants/queues.js +1 -0
- package/lib/queue/_manager.js +22 -23
- package/package.json +1 -1
package/lib/constants/queues.js
CHANGED
package/lib/queue/_manager.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
class
|
|
1
|
+
class QueueProcessor {
|
|
2
2
|
constructor () {
|
|
3
|
-
this.
|
|
3
|
+
this.queue = []
|
|
4
|
+
this.is_processing = false
|
|
4
5
|
}
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return true
|
|
7
|
+
enqueue (message, handler = (payload) => {}, onComplete = (message, result) => {}) {
|
|
8
|
+
this.queue.push(message)
|
|
9
|
+
if (!this.is_processing) {
|
|
10
|
+
this.process(handler, onComplete)
|
|
11
|
+
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
queue.current_size = queue.current_size - 1
|
|
17
|
-
this.queues.set(queue_name, queue)
|
|
14
|
+
async process (handler = (payload) => {}, onComplete = (message, result) => {}) {
|
|
15
|
+
this.is_processing = true
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
while (this.queue.length) {
|
|
18
|
+
const message = this.queue.shift()
|
|
19
|
+
const { content } = message
|
|
20
|
+
const payload = JSON.parse(Buffer.from(content).toString('utf-8'))
|
|
21
|
+
const result = await handler(payload)
|
|
22
|
+
onComplete(message, result)
|
|
22
23
|
}
|
|
24
|
+
this.is_processing = false
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
current_size: 0,
|
|
28
|
-
max_size
|
|
29
|
-
})
|
|
27
|
+
requeue (message) {
|
|
28
|
+
this.queue.push(message)
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
size (
|
|
33
|
-
return this.
|
|
31
|
+
size () {
|
|
32
|
+
return this.queue.length
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
module.exports =
|
|
36
|
+
module.exports = QueueProcessor
|