Миграция "jembadb" => "^2.3.0"
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -22,7 +22,7 @@
|
|||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"he": "^1.2.0",
|
"he": "^1.2.0",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
"jembadb": "^2.2.0",
|
"jembadb": "^2.3.0",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
@@ -6379,9 +6379,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/jembadb": {
|
"node_modules/jembadb": {
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.3.0.tgz",
|
||||||
"integrity": "sha512-1ddK0F4hAvDPmiSqPkn8GMbG7O+mMTbEG8oSOM+XczW1gdpChKt699ewUdFlMmTAQsx4XC43WDfVZzulc4a+3w==",
|
"integrity": "sha512-Jrvbe+4a3ULZvYmM6VnIK6mGFegPELbAppSYTTvPUeMmndNVOAVr1RDHKEiV8ccLanv1xWnJYiCo1mdnepR/Cg==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.4.0"
|
"node": ">=14.4.0"
|
||||||
}
|
}
|
||||||
@@ -16229,9 +16229,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"jembadb": {
|
"jembadb": {
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.3.0.tgz",
|
||||||
"integrity": "sha512-1ddK0F4hAvDPmiSqPkn8GMbG7O+mMTbEG8oSOM+XczW1gdpChKt699ewUdFlMmTAQsx4XC43WDfVZzulc4a+3w=="
|
"integrity": "sha512-Jrvbe+4a3ULZvYmM6VnIK6mGFegPELbAppSYTTvPUeMmndNVOAVr1RDHKEiV8ccLanv1xWnJYiCo1mdnepR/Cg=="
|
||||||
},
|
},
|
||||||
"jest-worker": {
|
"jest-worker": {
|
||||||
"version": "27.3.1",
|
"version": "27.3.1",
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"he": "^1.2.0",
|
"he": "^1.2.0",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
"jembadb": "^2.2.0",
|
"jembadb": "^2.3.0",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
let instance = null;
|
let instance = null;
|
||||||
|
|
||||||
const defaultTimeout = 15*1000;//15 sec
|
const defaultTimeout = 15*1000;//15 sec
|
||||||
const exitSignals = ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP', 'uncaughtException', 'SIGUSR2'];
|
const exitSignals = ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP', 'uncaughtException'];
|
||||||
|
|
||||||
//singleton
|
//singleton
|
||||||
class AsyncExit {
|
class AsyncExit {
|
||||||
constructor() {
|
constructor(signals = exitSignals, codeOnSignal = 2) {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
this.onSignalCallbacks = new Map();
|
this.onSignalCallbacks = new Map();
|
||||||
this.callbacks = new Map();
|
this.callbacks = new Map();
|
||||||
this.afterCallbacks = new Map();
|
this.afterCallbacks = new Map();
|
||||||
this.exitTimeout = defaultTimeout;
|
this.exitTimeout = defaultTimeout;
|
||||||
this.inited = false;
|
|
||||||
|
this._init(signals, codeOnSignal);
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(signals = exitSignals, codeOnSignal = 2) {
|
_init(signals, codeOnSignal) {
|
||||||
if (this.inited)
|
|
||||||
throw new Error('AsyncExit: initialized already');
|
|
||||||
|
|
||||||
const runSingalCallbacks = async(signal) => {
|
const runSingalCallbacks = async(signal) => {
|
||||||
for (const signalCallback of this.onSignalCallbacks.keys()) {
|
for (const signalCallback of this.onSignalCallbacks.keys()) {
|
||||||
try {
|
try {
|
||||||
@@ -38,8 +37,6 @@ class AsyncExit {
|
|||||||
this.exit(codeOnSignal);
|
this.exit(codeOnSignal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSignal(signalCallback) {
|
onSignal(signalCallback) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class JembaConnManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
this.inited = false;
|
this.inited = false;
|
||||||
|
this._db = {};
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
@@ -28,6 +29,8 @@ class JembaConnManager {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this._db = {};
|
this._db = {};
|
||||||
|
|
||||||
|
ayncExit.add(this.close.bind(this));
|
||||||
|
|
||||||
for (const dbConfig of this.config.jembaDb) {
|
for (const dbConfig of this.config.jembaDb) {
|
||||||
const dbPath = `${this.config.dataDir}/db/${dbConfig.dbName}`;
|
const dbPath = `${this.config.dataDir}/db/${dbConfig.dbName}`;
|
||||||
|
|
||||||
@@ -44,6 +47,7 @@ class JembaConnManager {
|
|||||||
} else {
|
} else {
|
||||||
dbConn = new JembaDb();
|
dbConn = new JembaDb();
|
||||||
}
|
}
|
||||||
|
this._db[dbConfig.dbName] = dbConn;
|
||||||
|
|
||||||
log(`Open "${dbConfig.dbName}" begin`);
|
log(`Open "${dbConfig.dbName}" begin`);
|
||||||
await dbConn.lock({
|
await dbConn.lock({
|
||||||
@@ -54,11 +58,12 @@ class JembaConnManager {
|
|||||||
tableDefaults: {
|
tableDefaults: {
|
||||||
cacheSize: dbConfig.cacheSize,
|
cacheSize: dbConfig.cacheSize,
|
||||||
compressed: dbConfig.compressed,
|
compressed: dbConfig.compressed,
|
||||||
forceFileClosing: dbConfig.forceFileClosing
|
forceFileClosing: dbConfig.forceFileClosing,
|
||||||
|
typeCompatMode: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dbConfig.openAll) {
|
if (dbConfig.openAll || forceAutoRepair || dbConfig.autoRepair) {
|
||||||
try {
|
try {
|
||||||
await dbConn.openAll();
|
await dbConn.openAll();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -87,21 +92,15 @@ class JembaConnManager {
|
|||||||
if (applied.length)
|
if (applied.length)
|
||||||
log(`${applied.length} migrations applied to "${dbConfig.dbName}"`);
|
log(`${applied.length} migrations applied to "${dbConfig.dbName}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._db[dbConfig.dbName] = dbConn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ayncExit.add(this.close.bind(this));
|
|
||||||
|
|
||||||
this.inited = true;
|
this.inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
if (!this.inited)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (const dbConfig of this.config.jembaDb) {
|
for (const dbConfig of this.config.jembaDb) {
|
||||||
await this._db[dbConfig.dbName].unlock();
|
if (this._db[dbConfig.dbName])
|
||||||
|
await this._db[dbConfig.dbName].unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._db = {};
|
this._db = {};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ const http = require('http');
|
|||||||
const WebSocket = require ('ws');
|
const WebSocket = require ('ws');
|
||||||
|
|
||||||
const ayncExit = new (require('./core/AsyncExit'))();
|
const ayncExit = new (require('./core/AsyncExit'))();
|
||||||
ayncExit.init();
|
|
||||||
|
|
||||||
let log = null;
|
let log = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user