cgserver 13.2.3 → 13.2.5
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.
|
@@ -118,6 +118,9 @@ class MongoExt {
|
|
|
118
118
|
get debug() {
|
|
119
119
|
return this._mongocfg.debug;
|
|
120
120
|
}
|
|
121
|
+
get dbName() {
|
|
122
|
+
return this._connection?.name || "unknown";
|
|
123
|
+
}
|
|
121
124
|
_connection = null;
|
|
122
125
|
get connection() {
|
|
123
126
|
return this._connection;
|
|
@@ -140,11 +143,18 @@ class MongoExt {
|
|
|
140
143
|
this._mongocfg.options.dbName = this._mongocfg.database;
|
|
141
144
|
this._connection = mongoose_2.default.createConnection("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
|
|
142
145
|
this._connection = this._connection.useDb(this._mongocfg.database);
|
|
143
|
-
this._connection.
|
|
146
|
+
this._connection.once("open", this.onOpen.bind(this));
|
|
144
147
|
this._connection.on("close", this.onClose.bind(this));
|
|
145
148
|
this._connection.on("connectionCreated", this.onConnect.bind(this));
|
|
146
149
|
this._connection.on("connectionClosed", this.onDisconnect.bind(this));
|
|
147
150
|
await this._connection.asPromise();
|
|
151
|
+
while (this._connection.readyState != mongoose_1.ConnectionStates.connected) {
|
|
152
|
+
if (this._connection.readyState != mongoose_1.ConnectionStates.connecting) {
|
|
153
|
+
Log_1.gLog.error("MongoDB connection is not ready, please check the connection settings. Current state: " + this._connection.readyState);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
await Core_1.core.sleep(100);
|
|
157
|
+
}
|
|
148
158
|
console.log("mongo connect success! db=" + this._connection.name);
|
|
149
159
|
return true;
|
|
150
160
|
}
|
|
@@ -155,7 +165,10 @@ class MongoExt {
|
|
|
155
165
|
this._cur_connecting_count--;
|
|
156
166
|
}
|
|
157
167
|
close(force = false) {
|
|
158
|
-
|
|
168
|
+
if (!this._connection) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this._connection.close(force);
|
|
159
172
|
}
|
|
160
173
|
registerInitCb(cb) {
|
|
161
174
|
this._init_cbs.push(cb);
|
|
@@ -5,13 +5,13 @@ const Log_1 = require("../Logic/Log");
|
|
|
5
5
|
let MongoActionCheck = function (ret = null) {
|
|
6
6
|
return function (target, propertyName, descriptor) {
|
|
7
7
|
let method = descriptor.value;
|
|
8
|
-
descriptor.value = function () {
|
|
8
|
+
descriptor.value = async function () {
|
|
9
9
|
let self = this;
|
|
10
10
|
try {
|
|
11
11
|
let start_time = Date.now();
|
|
12
|
-
ret = method.apply(this, arguments);
|
|
12
|
+
ret = await method.apply(this, arguments);
|
|
13
13
|
let dt = Date.now() - start_time;
|
|
14
|
-
self.debug && Log_1.gLog.info({ key: method.name, dt, arguments });
|
|
14
|
+
self.debug && Log_1.gLog.info({ key: method.name, dt, arguments, dbName: self.dbName });
|
|
15
15
|
return ret;
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
@@ -58,6 +58,7 @@ export declare class MongoExt {
|
|
|
58
58
|
get curConnectingCount(): number;
|
|
59
59
|
get isValid(): boolean;
|
|
60
60
|
get debug(): boolean;
|
|
61
|
+
get dbName(): string;
|
|
61
62
|
protected _connection: mongoose.Connection;
|
|
62
63
|
get connection(): mongoose.Connection;
|
|
63
64
|
get connected(): boolean;
|