@rpcbase/server 0.171.0 → 0.172.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.172.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@rpcbase/agent": "0.29.0",
|
|
14
14
|
"@rpcbase/std": "0.5.0",
|
|
15
15
|
"body-parser": "1.20.1",
|
|
16
|
-
"bull": "4.10.
|
|
16
|
+
"bull": "4.10.4",
|
|
17
17
|
"connect-redis": "6.1.3",
|
|
18
18
|
"cors": "2.8.5",
|
|
19
19
|
"debug": "4.3.4",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"glob": "8.1.0",
|
|
24
24
|
"lodash": "4.17.21",
|
|
25
25
|
"mkdirp": "1.0.4",
|
|
26
|
-
"mongoose": "6.9.
|
|
26
|
+
"mongoose": "6.9.2",
|
|
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.
|
|
32
|
+
"yargs": "17.7.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -9,19 +9,22 @@ const dispatch_queue = require("./dispatch_queue")
|
|
|
9
9
|
|
|
10
10
|
const log = debug("rb:queue:listener")
|
|
11
11
|
|
|
12
|
+
const MAX_RETRIES = 100
|
|
13
|
+
let current_retry = 0
|
|
14
|
+
|
|
12
15
|
// Listens for mongodb change events,
|
|
13
16
|
// when a document is created, updated or deleted, dispatch job message
|
|
14
17
|
|
|
15
18
|
// mongoose middleware used for delete events
|
|
16
19
|
const mongoose_delete_plugin = (schema) => {
|
|
17
20
|
schema.pre("deleteOne", function(next) {
|
|
18
|
-
throw new Error("rts
|
|
21
|
+
throw new Error("rts:deleteOne is deprecated, use findOneAndDelete")
|
|
19
22
|
})
|
|
20
23
|
|
|
21
24
|
// TODO: add other delete operations
|
|
22
25
|
// https://mongoosejs.com/docs/queries.html
|
|
23
26
|
schema.post("findOneAndDelete", function(doc) {
|
|
24
|
-
log("queue
|
|
27
|
+
log("queue:findOneAndDelete", "dispatch_doc_change NYI")
|
|
25
28
|
log("DEL PLUGIN", doc)
|
|
26
29
|
const model_name = this.model.modelName
|
|
27
30
|
dispatch_queue(queue, model_name, "delete", doc)
|
|
@@ -50,24 +53,41 @@ const get_dispatch_change_handler = (model_name, filter_fn) => (change) => {
|
|
|
50
53
|
|
|
51
54
|
const register_model_emitter = (model_name, filter_fn) => {
|
|
52
55
|
log("registering emitter for", model_name)
|
|
56
|
+
|
|
53
57
|
const model = mongoose.model(model_name)
|
|
54
58
|
// TODO: implement delete operation fullDocument retrieve,
|
|
55
59
|
// when this is released https://jira.mongodb.org/browse/SERVER-36941
|
|
56
60
|
// this is done via a plugin right now
|
|
61
|
+
// https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ChangeStreamOptions.html
|
|
57
62
|
const emitter = model.watch({fullDocument: "updateLookup"})
|
|
58
63
|
|
|
59
64
|
emitter.on("change", get_dispatch_change_handler(model_name, filter_fn))
|
|
60
65
|
|
|
61
66
|
emitter.on("error", (err) => {
|
|
62
|
-
log("server
|
|
67
|
+
log("server:queue:register_queue_listener: change listener emitter got error", err)
|
|
63
68
|
})
|
|
64
69
|
|
|
65
70
|
emitter.on("close", (arg, arg2) => {
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
// console.log("close", arg, arg2)
|
|
72
|
+
// TODO: investigate why we disconnect here and can't reconnect easily
|
|
73
|
+
current_retry++
|
|
74
|
+
const timeout = 1000 * current_retry
|
|
75
|
+
console.log("queue_listener: emitter closed, model:", model_name, "retrying in", timeout)
|
|
76
|
+
|
|
77
|
+
if (current_retry > MAX_RETRIES) {
|
|
78
|
+
console.log("queue listener reached max retries, exiting with failure")
|
|
79
|
+
process.exit(1)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setTimeout(() => {
|
|
69
84
|
register_model_emitter(model_name, filter_fn)
|
|
70
|
-
})
|
|
85
|
+
}, timeout)
|
|
86
|
+
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
emitter.on("end", (arg) => {
|
|
90
|
+
console.log("emitter ENDED", arg)
|
|
71
91
|
})
|
|
72
92
|
}
|
|
73
93
|
|
|
@@ -78,7 +98,6 @@ const register_queue_listener = (filter_fn) => {
|
|
|
78
98
|
mongoose.plugin(mongoose_delete_plugin)
|
|
79
99
|
|
|
80
100
|
mongoose.connection.once("open", () => {
|
|
81
|
-
log("queue_listener mongoose connection opened")
|
|
82
101
|
const models = mongoose.modelNames()
|
|
83
102
|
models.forEach((model_name) => register_model_emitter(model_name, filter_fn))
|
|
84
103
|
})
|