@rpcbase/server 0.172.0 → 0.173.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.173.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@rpcbase/agent": "0.
|
|
14
|
-
"@rpcbase/std": "0.
|
|
15
|
-
"body-parser": "1.20.
|
|
13
|
+
"@rpcbase/agent": "0.30.0",
|
|
14
|
+
"@rpcbase/std": "0.6.0",
|
|
15
|
+
"body-parser": "1.20.2",
|
|
16
16
|
"bull": "4.10.4",
|
|
17
17
|
"connect-redis": "6.1.3",
|
|
18
18
|
"cors": "2.8.5",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"express-session": "1.17.3",
|
|
23
23
|
"glob": "8.1.0",
|
|
24
24
|
"lodash": "4.17.21",
|
|
25
|
-
"mkdirp": "1.
|
|
26
|
-
"mongoose": "6.
|
|
25
|
+
"mkdirp": "2.1.3",
|
|
26
|
+
"mongoose": "6.10.0",
|
|
27
27
|
"picocolors": "1.0.0",
|
|
28
28
|
"postmark": "3.0.15",
|
|
29
29
|
"redis": "4.6.4",
|
|
30
30
|
"request-ip": "3.3.0",
|
|
31
31
|
"validator": "13.9.0",
|
|
32
|
-
"yargs": "17.7.
|
|
32
|
+
"yargs": "17.7.1"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const debug = require("debug")
|
|
3
|
+
const _get = require("lodash/get")
|
|
4
|
+
const _set = require("lodash/set")
|
|
3
5
|
|
|
4
6
|
const mongoose = require("../mongoose")
|
|
5
7
|
const queue = require("./index")
|
|
@@ -9,8 +11,11 @@ const dispatch_queue = require("./dispatch_queue")
|
|
|
9
11
|
|
|
10
12
|
const log = debug("rb:queue:listener")
|
|
11
13
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
+
const RETRY_MINIMUM_DELAY = 10
|
|
15
|
+
const MAX_RETRIES = 16
|
|
16
|
+
const retry_counters = {}
|
|
17
|
+
// TODO: reset retry counters when connection becomes healthy again
|
|
18
|
+
|
|
14
19
|
|
|
15
20
|
// Listens for mongodb change events,
|
|
16
21
|
// when a document is created, updated or deleted, dispatch job message
|
|
@@ -70,20 +75,21 @@ const register_model_emitter = (model_name, filter_fn) => {
|
|
|
70
75
|
emitter.on("close", (arg, arg2) => {
|
|
71
76
|
// console.log("close", arg, arg2)
|
|
72
77
|
// TODO: investigate why we disconnect here and can't reconnect easily
|
|
73
|
-
current_retry
|
|
74
|
-
|
|
75
|
-
console.log("queue_listener: emitter closed, model:", model_name, "retrying in", timeout)
|
|
78
|
+
const current_retry = _get(retry_counters, model_name, 0)
|
|
79
|
+
_set(retry_counters, model_name, current_retry + 1)
|
|
76
80
|
|
|
77
81
|
if (current_retry > MAX_RETRIES) {
|
|
78
|
-
console.log("queue listener reached max retries, exiting with failure")
|
|
82
|
+
console.log("queue listener reached max retries for:", model_name, "exiting with failure")
|
|
79
83
|
process.exit(1)
|
|
80
84
|
return
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
const timeout = RETRY_MINIMUM_DELAY + 10 * Math.pow(2, current_retry)
|
|
88
|
+
console.log("queue_listener: emitter closed, model:", model_name, "retrying in", timeout)
|
|
89
|
+
|
|
83
90
|
setTimeout(() => {
|
|
84
91
|
register_model_emitter(model_name, filter_fn)
|
|
85
92
|
}, timeout)
|
|
86
|
-
|
|
87
93
|
})
|
|
88
94
|
|
|
89
95
|
emitter.on("end", (arg) => {
|
|
@@ -98,8 +104,10 @@ const register_queue_listener = (filter_fn) => {
|
|
|
98
104
|
mongoose.plugin(mongoose_delete_plugin)
|
|
99
105
|
|
|
100
106
|
mongoose.connection.once("open", () => {
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
process.nextTick(() => {
|
|
108
|
+
const models = mongoose.modelNames()
|
|
109
|
+
models.forEach((model_name) => register_model_emitter(model_name, filter_fn))
|
|
110
|
+
})
|
|
103
111
|
})
|
|
104
112
|
}
|
|
105
113
|
|