@rpcbase/server 0.72.0 → 0.73.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 CHANGED
@@ -11,6 +11,10 @@ const mkdirp = require("mkdirp")
11
11
  // TODO: verify mongod and redis-sever and elasticsearch executables are present
12
12
  // and have the right version
13
13
 
14
+ const NO_PRINT_LIST = [
15
+ // "database",
16
+ ]
17
+
14
18
  // load env
15
19
  const get_env = () => {
16
20
  const env_path = path.join(process.cwd(), "./.env")
@@ -19,17 +23,22 @@ const get_env = () => {
19
23
  return env
20
24
  }
21
25
 
22
- const init_processes = () => {
26
+ const init_processes = (args) => {
23
27
  const env = get_env()
24
28
 
25
29
  const infrastructure_conf_dir = path.join(__dirname, "../infrastructure")
26
30
 
27
- // create data dirs
31
+ // db storage
28
32
  const db_path = path.join(process.cwd(), "../infrastructure/data/database/db/")
29
- const db_logs_path = path.join(process.cwd(), "../infrastructure/data/database/log/")
30
33
 
34
+ // db log file
35
+ const db_logs_path = path.join(process.cwd(), "../infrastructure/data/database/log/logs.txt")
36
+
37
+ // session-store + worker-queue
31
38
  const session_store_dir = path.join(process.cwd(), "../infrastructure/data/session-store/data")
39
+ const session_store_logs_path = path.join(process.cwd(), "../infrastructure/data/session-store/log/logs.txt")
32
40
  const worker_queue_dir = path.join(process.cwd(), "../infrastructure/data/worker-queue/data")
41
+ const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
33
42
 
34
43
  // TODO: add a redis cache
35
44
  const processes = [
@@ -46,14 +55,16 @@ const init_processes = () => {
46
55
  {
47
56
  name: "database",
48
57
  dirs: [
49
- db_path, db_logs_path
58
+ db_path,
59
+ path.dirname(db_logs_path),
50
60
  ],
51
61
  cmd: ["mongod", [
52
62
  "--quiet",
53
63
  "--dbpath", db_path,
54
64
  "--port", env.DATABASE_PORT,
55
65
  // "--bind_ip_all",
56
- // "--logpath", "/var/log/logs.txt",
66
+ // if in verbose mode, print to stdout, else write to file
67
+ ...(args.verbose ? [] : ["--logpath", db_logs_path]),
57
68
  "--replSet", "rs0"
58
69
  ]]
59
70
  },
@@ -62,11 +73,13 @@ const init_processes = () => {
62
73
  name: "session-store",
63
74
  dirs: [
64
75
  session_store_dir,
76
+ path.dirname(session_store_logs_path),
65
77
  ],
66
78
  cmd: ["redis-server", [
67
79
  path.join(infrastructure_conf_dir, "./redis/redis.conf"),
68
80
  "--dir", session_store_dir,
69
81
  "--port", env.SESSION_STORE_PORT,
82
+ ...(args.verbose ? [] : ["--logfile", session_store_logs_path]),
70
83
  ]]
71
84
  },
72
85
  // worker-queue
@@ -74,11 +87,13 @@ const init_processes = () => {
74
87
  name: "worker-queue",
75
88
  dirs: [
76
89
  worker_queue_dir,
90
+ path.dirname(worker_queue_logs_path),
77
91
  ],
78
92
  cmd: ["redis-server", [
79
93
  path.join(infrastructure_conf_dir, "./redis/redis.conf"),
80
94
  "--dir", worker_queue_dir,
81
95
  "--port", env.WORKER_QUEUE_PORT,
96
+ ...(args.verbose ? [] : ["--logfile", worker_queue_logs_path]),
82
97
  ]]
83
98
  },
84
99
  ]
@@ -118,22 +133,32 @@ const init_processes = () => {
118
133
 
119
134
  // TODO: run each native process from list
120
135
  // TODO: handle process close
121
- const run_native = (infrastructure_dir, proj_prefix) => {
122
- console.log("running in NATIVE mode")
136
+ const run_native = (infrastructure_dir, proj_prefix, args) => {
137
+ console.log(`running in ${colors.bold(colors.magenta("NATIVE"))} mode`)
123
138
 
124
- const processes = init_processes()
139
+ const processes = init_processes(args)
125
140
 
126
141
  const run_process = (item) => {
127
- // console.log("start process", item)
142
+ // console.log("run_native:run_process:item", item)
128
143
  const ps = spawn(item.cmd[0], item.cmd[1], {env: {...process.env, CONTAINER_MODE: "native"}})
129
144
 
130
- ps.stdout.on("data", (data) => {
131
- process.stdout.write(`${colors.green(item.name)}: ${data.toString()}`)
132
- })
145
+ // TODO: add flag to force print
146
+ if (!NO_PRINT_LIST.includes(item.name)) {
133
147
 
134
- ps.stderr.on("data", (data) => {
135
- process.stderr.write(`${item.name}: ${data.toString()}`)
136
- })
148
+ let prefix = ""
149
+ // avoid printing [server] server:
150
+ if (!args.verbose && item.name !== "server") {
151
+ prefix = `${colors.green(item.name)}: `
152
+ }
153
+
154
+ ps.stdout.on("data", (data) => {
155
+ process.stdout.write(`${prefix}${data.toString()}`)
156
+ })
157
+
158
+ ps.stderr.on("data", (data) => {
159
+ process.stderr.write(`${prefix}${data.toString()}`)
160
+ })
161
+ }
137
162
  }
138
163
 
139
164
  const spawned = processes.map(run_process)
@@ -19,9 +19,9 @@ const start_server = async(args) => {
19
19
  const proj_prefix = path.basename(proj_parent_dir)
20
20
 
21
21
  if (runtime === "docker") {
22
- run_docker(infrastructure_dir, proj_prefix)
22
+ run_docker(infrastructure_dir, proj_prefix, args)
23
23
  } else if (runtime === "native") {
24
- run_native(infrastructure_dir, proj_prefix)
24
+ run_native(infrastructure_dir, proj_prefix, args)
25
25
  } else {
26
26
  throw new Error("unknown runtime")
27
27
  }
package/database.js CHANGED
@@ -24,6 +24,7 @@ module.exports = async() => {
24
24
  })
25
25
 
26
26
  mongoose.connection.on("disconnected", (arg) => {
27
+ // TODO: add tracing
27
28
  console.log("Mongoose disconnected", arg)
28
29
  })
29
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
- "@rpcbase/agent": "0.8.0",
13
+ "@rpcbase/agent": "0.9.0",
14
14
  "body-parser": "1.20.0",
15
15
  "connect-redis": "6.1.3",
16
16
  "cors": "2.8.5",
@@ -19,7 +19,7 @@
19
19
  "express": "4.18.1",
20
20
  "express-session": "1.17.3",
21
21
  "glob": "8.0.3",
22
- "mongoose": "6.3.6",
22
+ "mongoose": "6.4.0",
23
23
  "picocolors": "1.0.0",
24
24
  "postmark": "3.0.11",
25
25
  "redis": "4.1.0",