molly-db 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- package/main.js +4 -22
- package/module/_worker_.js +22 -7
- package/package.json +1 -1
package/main.js
CHANGED
@@ -15,30 +15,12 @@ function config( _config ) {
|
|
15
15
|
|
16
16
|
/* --------------------------------------------------------------------------------------- */
|
17
17
|
|
18
|
-
function startWorker(_path,_self){
|
19
|
-
return new Promise((response,reject)=>{
|
20
|
-
const wrk = new worker.Worker(
|
21
|
-
_path,{ workerData:_self,
|
22
|
-
env: worker.SHARE_ENV,
|
23
|
-
}); wrk.on('exit',(err)=>{ console.log(err);
|
24
|
-
response(startWorker(_path,_self));
|
25
|
-
}); wrk.on('message',(msg)=>{
|
26
|
-
console.log(msg); response(msg)
|
27
|
-
});
|
28
|
-
});
|
29
|
-
}
|
30
|
-
|
31
|
-
/* --------------------------------------------------------------------------------------- */
|
32
|
-
|
33
18
|
class molly_db{
|
34
19
|
|
35
|
-
constructor( opt ){
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
this.path = opt.path.replace(/^\./,process.cwd());
|
40
|
-
this.workerPath = `${__dirname}/module/_worker_.js`;
|
41
|
-
return startWorker( this.workerPath,this );
|
20
|
+
constructor( opt ){ if( opt.pass )
|
21
|
+
this.pass = opt.pass; this.port = opt.port || 27017;
|
22
|
+
this.path = opt.path.replace( /^\./,process.cwd() );
|
23
|
+
return require(`${__dirname}/module/_worker_.js`)(this);
|
42
24
|
}
|
43
25
|
|
44
26
|
}
|
package/module/_worker_.js
CHANGED
@@ -2,13 +2,17 @@ const worker = require('worker_threads');
|
|
2
2
|
const readline = require('readline');
|
3
3
|
const crypto = require('./_crypto_');
|
4
4
|
const { Buffer } = require('buffer');
|
5
|
+
const cluster = require('cluster');
|
5
6
|
const fetch = require('axios');
|
6
7
|
const http = require('http');
|
7
8
|
const url = require('url');
|
8
9
|
const fs = require('fs');
|
9
10
|
|
10
|
-
|
11
|
+
/* --------------------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
let query;
|
11
14
|
const db = new Object();
|
15
|
+
|
12
16
|
/* --------------------------------------------------------------------------------------- */
|
13
17
|
|
14
18
|
function _init_(){
|
@@ -25,11 +29,22 @@ function app(req,res){
|
|
25
29
|
|
26
30
|
/* --------------------------------------------------------------------------------------- */
|
27
31
|
|
28
|
-
(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
});
|
32
|
+
module.exports = (args)=>{ query = args;
|
33
|
+
return new Promise((response,reject)=>{
|
34
|
+
if (cluster.isPrimary) { const worker = cluster.fork();
|
35
|
+
cluster.on('exit', (worker, code, signal) => { cluster.fork();
|
36
|
+
console.log(`worker ${worker.process.pid} died`);
|
37
|
+
}); worker.on('message', (msg)=>{ console.log(msg); response(); });
|
38
|
+
worker.on('exit', (msg)=>{ reject(msg); });
|
39
|
+
} else {
|
40
|
+
http.createServer( app ).listen( query.port,()=>{
|
41
|
+
_init_().then(()=>{ process.send({
|
42
|
+
workerID: process.pid, port: query.port,
|
43
|
+
protocol: 'HTTP', status: 'started',
|
44
|
+
})}).catch(e=>{ console.log(e); });
|
45
|
+
});
|
46
|
+
}
|
47
|
+
});
|
48
|
+
}
|
34
49
|
|
35
50
|
/* --------------------------------------------------------------------------------------- */
|