@rpcbase/server 0.94.0 → 0.95.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.
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
|
|
2
|
+
const debug = require("debug")
|
|
3
|
+
|
|
4
|
+
const log = debug("rb:coverage")
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
const is_production = process.env.NODE_ENV === "production"
|
|
6
8
|
|
|
7
9
|
module.exports = (app) => {
|
|
8
10
|
app.post("/api/__dev_save_coverage", (req, res) => {
|
|
9
|
-
|
|
11
|
+
if (is_production) {
|
|
12
|
+
log("refusing to save coverage in production")
|
|
13
|
+
return res.status(500).end()
|
|
14
|
+
}
|
|
15
|
+
// log("sending coverage for", req.body.path_key)
|
|
10
16
|
res.json(global.__coverage__)
|
|
11
17
|
})
|
|
12
18
|
}
|
package/package.json
CHANGED
package/queue/index.js
CHANGED
|
@@ -11,8 +11,9 @@ let worker_queue
|
|
|
11
11
|
|
|
12
12
|
const worker_add = async(task_name, payload, options) => {
|
|
13
13
|
const res = await worker_queue.add({task_name, payload}, options)
|
|
14
|
-
// myQueue.add(data, { repeat: { cron: '15 3 * * *' } });
|
|
15
14
|
console.log("created task:", task_name, res.id)
|
|
15
|
+
console.log(payload)
|
|
16
|
+
console.log("\n")
|
|
16
17
|
return res
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -47,9 +48,11 @@ const start_worker = async() => {
|
|
|
47
48
|
worker_queue.process(async(job) => {
|
|
48
49
|
try {
|
|
49
50
|
const {task_name, payload} = job.data
|
|
51
|
+
|
|
50
52
|
console.log(`start job ${job.id} ${task_name}`)
|
|
51
|
-
|
|
53
|
+
|
|
52
54
|
const task_fn = tasks_list[task_name]
|
|
55
|
+
|
|
53
56
|
const res = await task_fn(payload)
|
|
54
57
|
return res
|
|
55
58
|
} catch (err) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
const debug = require("debug")
|
|
3
|
+
|
|
2
4
|
const mongoose = require("../mongoose")
|
|
3
5
|
const queue = require("./index")
|
|
4
6
|
|
|
5
7
|
const dispatch_queue = require("./dispatch_queue")
|
|
6
8
|
|
|
9
|
+
const log = debug("rb:queue:listener")
|
|
7
10
|
|
|
8
11
|
// Listens for mongodb change events,
|
|
9
12
|
// when a document is created, updated or deleted, dispatch job message
|
|
@@ -18,8 +21,8 @@ const mongoose_delete_plugin = (schema) => {
|
|
|
18
21
|
// TODO: add other delete operations
|
|
19
22
|
// https://mongoosejs.com/docs/queries.html
|
|
20
23
|
schema.post("findOneAndDelete", function(doc) {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
log("queue::findOneAndDelete", "dispatch_doc_change NYI")
|
|
25
|
+
log("DEL PLUGIN", doc)
|
|
23
26
|
const model_name = this.model.modelName
|
|
24
27
|
dispatch_queue(queue, model_name, "delete", doc)
|
|
25
28
|
})
|
|
@@ -35,30 +38,35 @@ const get_dispatch_change_handler = (model_name) => (change) => {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
mongoose.plugin(mongoose_delete_plugin)
|
|
41
|
+
const register_model_emitter = (model_name) => {
|
|
42
|
+
const model = mongoose.model(model_name)
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
// TODO: implement delete operation fullDocument retrieve,
|
|
45
|
+
// when this is released https://jira.mongodb.org/browse/SERVER-36941
|
|
46
|
+
// this is done via a plugin right now
|
|
47
|
+
const emitter = model.watch({fullDocument: "updateLookup"})
|
|
48
|
+
|
|
49
|
+
emitter.on("change", get_dispatch_change_handler(model_name))
|
|
50
|
+
|
|
51
|
+
emitter.on("error", (err) => {
|
|
52
|
+
log("server::queue::register_queue_listener:: change listener emitter got error", err)
|
|
53
|
+
})
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
emitter.on("close", (arg, arg2) => {
|
|
56
|
+
log("queue_listener: emitter closed, model:", model_name, "retrying")
|
|
57
|
+
register_model_emitter(model_name)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
46
60
|
|
|
47
|
-
// TODO: implement delete operation fullDocument retrieve,
|
|
48
|
-
// when this is released https://jira.mongodb.org/browse/SERVER-36941
|
|
49
|
-
// this is done via a plugin right now
|
|
50
|
-
const emitter = model.watch({fullDocument: "updateLookup"})
|
|
51
61
|
|
|
52
|
-
emitter.on("change", get_dispatch_change_handler(model_name))
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
const register_queue_listener = async() => {
|
|
64
|
+
// register the mongoose delete plugin
|
|
65
|
+
mongoose.plugin(mongoose_delete_plugin)
|
|
66
|
+
|
|
67
|
+
const models = mongoose.modelNames()
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
console.log("queue_listener: emitter closed, model:", model_name)
|
|
60
|
-
})
|
|
61
|
-
})
|
|
69
|
+
models.forEach(register_model_emitter)
|
|
62
70
|
|
|
63
71
|
}
|
|
64
72
|
|