@rpcbase/server 0.307.0 → 0.309.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/cli/run_native.js +6 -3
- package/database.js +22 -4
- package/package.json +1 -1
package/cli/run_native.js
CHANGED
|
@@ -47,8 +47,11 @@ const get_processes = (args) => {
|
|
|
47
47
|
const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
|
|
48
48
|
|
|
49
49
|
const has_uds = true
|
|
50
|
+
const uds_root_path = `/tmp/sockets-${env.RB_APP_NAME}/`
|
|
51
|
+
if (has_uds && !fs.existsSync(uds_root_path)) {
|
|
52
|
+
mkdirp.sync(uds_root_path)
|
|
53
|
+
}
|
|
50
54
|
|
|
51
|
-
// TODO: add a redis cache
|
|
52
55
|
const processes = [
|
|
53
56
|
// web server
|
|
54
57
|
{
|
|
@@ -72,9 +75,9 @@ const get_processes = (args) => {
|
|
|
72
75
|
cmd: ["mongod", [
|
|
73
76
|
"--quiet",
|
|
74
77
|
"--dbpath", db_path,
|
|
78
|
+
"--bind_ip", "127.0.0.1", // TODO: bind to 0.0.0.0 here when going multinodes
|
|
75
79
|
"--port", env.DATABASE_PORT,
|
|
76
|
-
...(has_uds ? ["--unixSocketPrefix",
|
|
77
|
-
// "--bind_ip_all",
|
|
80
|
+
...(has_uds ? ["--unixSocketPrefix", uds_root_path, "--filePermissions", "0700"] : []),
|
|
78
81
|
// if in verbose mode, print to stdout, else write to file
|
|
79
82
|
...(args.verbose ? [] : ["--logpath", db_logs_path]),
|
|
80
83
|
"--replSet", "rs0"
|
package/database.js
CHANGED
|
@@ -26,9 +26,25 @@ if (typeof RB_APP_NAME !== "string") {
|
|
|
26
26
|
throw new Error("expected RB_APP_NAME in env to be a string")
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const hostname = is_docker() ? "database" : "127.0.0.1"
|
|
30
29
|
|
|
31
|
-
const
|
|
30
|
+
const get_mongo_url = () => {
|
|
31
|
+
const conn_suffix = `?directConnection=true&replicaSet=rs0`
|
|
32
|
+
|
|
33
|
+
let url
|
|
34
|
+
|
|
35
|
+
// connect via tcp in docker
|
|
36
|
+
if (is_docker()) {
|
|
37
|
+
const hostname = "database" // "127.0.0.1"
|
|
38
|
+
url = `mongodb://${hostname}:${DATABASE_PORT}/${conn_suffix}`
|
|
39
|
+
}
|
|
40
|
+
// when running natively, prefer the unix socket
|
|
41
|
+
else {
|
|
42
|
+
const uds_root_path = `/tmp/sockets-${RB_APP_NAME}/`
|
|
43
|
+
url = `mongodb://${encodeURIComponent(uds_root_path)}mongodb-${DATABASE_PORT}.sock`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return url
|
|
47
|
+
}
|
|
32
48
|
|
|
33
49
|
|
|
34
50
|
// TODO: handle multiple databases, remove RB_APP_NAME env ??
|
|
@@ -49,13 +65,15 @@ module.exports = async(...database_names) => {
|
|
|
49
65
|
console.log("mongoose connection error", err)
|
|
50
66
|
})
|
|
51
67
|
|
|
68
|
+
const mongo_url = get_mongo_url()
|
|
52
69
|
console.log("connect mongo_url", mongo_url)
|
|
53
70
|
|
|
54
71
|
const connect_opts = {
|
|
55
|
-
|
|
72
|
+
dbName: RB_APP_NAME,
|
|
73
|
+
minPoolSize: 8,
|
|
56
74
|
// maxPoolSize: 1024 * 1024,
|
|
57
75
|
// TODO: setting this to a low value adds ~3s delay to requests... WHY
|
|
58
|
-
maxPoolSize:
|
|
76
|
+
maxPoolSize: 512,
|
|
59
77
|
family: 4, // force ipv4
|
|
60
78
|
driverInfo: {
|
|
61
79
|
name: `${pack.name}/database`,
|