@rpcbase/server 0.172.0 → 0.174.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.
|
@@ -25,7 +25,7 @@ console.log("session-store hostname", hostname, "port", SESSION_STORE_PORT)
|
|
|
25
25
|
|
|
26
26
|
let session_middleware = null
|
|
27
27
|
|
|
28
|
-
//
|
|
28
|
+
// EXTREME WARNING: docker issue
|
|
29
29
|
// when there is synchronous io redis client fails to connect
|
|
30
30
|
setTimeout(async() => {
|
|
31
31
|
if (!SESSION_STORE_PORT) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.174.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
|
+
// TODO: reset retry counters when connection becomes healthy again?
|
|
17
|
+
const retry_counters = {}
|
|
18
|
+
|
|
14
19
|
|
|
15
20
|
// Listens for mongodb change events,
|
|
16
21
|
// when a document is created, updated or deleted, dispatch job message
|
|
@@ -32,18 +37,7 @@ const mongoose_delete_plugin = (schema) => {
|
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
|
|
35
|
-
const get_dispatch_change_handler = (model_name
|
|
36
|
-
if (typeof filter_fn === "function") {
|
|
37
|
-
let ret
|
|
38
|
-
try {
|
|
39
|
-
ret = filter_fn(model_name, change)
|
|
40
|
-
} catch (err) {
|
|
41
|
-
console.log("get_dispatch_change_handler::filter_fn::error:", err)
|
|
42
|
-
}
|
|
43
|
-
if (!ret) {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
}
|
|
40
|
+
const get_dispatch_change_handler = (model_name) => (change) => {
|
|
47
41
|
const op = change.operationType
|
|
48
42
|
if (["insert", "update"].includes(op)) {
|
|
49
43
|
dispatch_queue(queue, model_name, op, change.fullDocument)
|
|
@@ -51,7 +45,7 @@ const get_dispatch_change_handler = (model_name, filter_fn) => (change) => {
|
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
|
|
54
|
-
const register_model_emitter = (model_name
|
|
48
|
+
const register_model_emitter = (model_name) => {
|
|
55
49
|
log("registering emitter for", model_name)
|
|
56
50
|
|
|
57
51
|
const model = mongoose.model(model_name)
|
|
@@ -61,7 +55,7 @@ const register_model_emitter = (model_name, filter_fn) => {
|
|
|
61
55
|
// https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ChangeStreamOptions.html
|
|
62
56
|
const emitter = model.watch({fullDocument: "updateLookup"})
|
|
63
57
|
|
|
64
|
-
emitter.on("change", get_dispatch_change_handler(model_name
|
|
58
|
+
emitter.on("change", get_dispatch_change_handler(model_name))
|
|
65
59
|
|
|
66
60
|
emitter.on("error", (err) => {
|
|
67
61
|
log("server:queue:register_queue_listener: change listener emitter got error", err)
|
|
@@ -70,20 +64,21 @@ const register_model_emitter = (model_name, filter_fn) => {
|
|
|
70
64
|
emitter.on("close", (arg, arg2) => {
|
|
71
65
|
// console.log("close", arg, arg2)
|
|
72
66
|
// 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)
|
|
67
|
+
const current_retry = _get(retry_counters, model_name, 0)
|
|
68
|
+
_set(retry_counters, model_name, current_retry + 1)
|
|
76
69
|
|
|
77
70
|
if (current_retry > MAX_RETRIES) {
|
|
78
|
-
console.log("queue listener reached max retries, exiting with failure")
|
|
71
|
+
console.log("queue listener reached max retries for:", model_name, "exiting with failure")
|
|
79
72
|
process.exit(1)
|
|
80
73
|
return
|
|
81
74
|
}
|
|
82
75
|
|
|
76
|
+
const timeout = RETRY_MINIMUM_DELAY + 10 * Math.pow(2, current_retry)
|
|
77
|
+
console.log("queue_listener: emitter closed, model:", model_name, "retrying in", timeout)
|
|
78
|
+
|
|
83
79
|
setTimeout(() => {
|
|
84
|
-
register_model_emitter(model_name
|
|
80
|
+
register_model_emitter(model_name)
|
|
85
81
|
}, timeout)
|
|
86
|
-
|
|
87
82
|
})
|
|
88
83
|
|
|
89
84
|
emitter.on("end", (arg) => {
|
|
@@ -92,14 +87,16 @@ const register_model_emitter = (model_name, filter_fn) => {
|
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
|
|
95
|
-
const register_queue_listener = (
|
|
90
|
+
const register_queue_listener = () => {
|
|
96
91
|
// register the mongoose delete plugin
|
|
97
92
|
log("registering mongoose_delete_plugin")
|
|
98
93
|
mongoose.plugin(mongoose_delete_plugin)
|
|
99
94
|
|
|
100
95
|
mongoose.connection.once("open", () => {
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
process.nextTick(() => {
|
|
97
|
+
const models = mongoose.modelNames()
|
|
98
|
+
models.forEach((model_name) => register_model_emitter(model_name))
|
|
99
|
+
})
|
|
103
100
|
})
|
|
104
101
|
}
|
|
105
102
|
|