cgserver 12.2.0 → 12.2.2
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.
|
@@ -150,13 +150,12 @@ class MongoExt {
|
|
|
150
150
|
if (this._inited) {
|
|
151
151
|
return false;
|
|
152
152
|
}
|
|
153
|
-
if (this._mongoDb) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
153
|
this._mongocfg = cfg;
|
|
157
154
|
this._inited = true;
|
|
158
155
|
Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
|
|
159
156
|
this._mongoClient = new mongo.MongoClient("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
|
|
157
|
+
this._mongoClient.on("open", this.onOpen.bind(this));
|
|
158
|
+
this._mongoClient.on("close", this.onClose.bind(this));
|
|
160
159
|
this._mongoClient.on("connectionCreated", this.onConnectionCreated.bind(this));
|
|
161
160
|
this._mongoClient.on("connectionReady", this.onConnectionReady.bind(this));
|
|
162
161
|
this._mongoClient.on("connectionClosed", this.onConnectionClosed.bind(this));
|
|
@@ -168,17 +167,9 @@ class MongoExt {
|
|
|
168
167
|
}
|
|
169
168
|
onConnectionReady(event) {
|
|
170
169
|
Log_1.gLog.info({ key: "mongo onConnectionReady", event });
|
|
171
|
-
this.onConnect();
|
|
172
|
-
this._mongoDb = this._mongoClient.db(this._mongocfg.database);
|
|
173
|
-
for (let i = 0; i < this._init_cbs.length; ++i) {
|
|
174
|
-
this._init_cbs[i]();
|
|
175
|
-
}
|
|
176
|
-
this._init_cbs = [];
|
|
177
170
|
}
|
|
178
171
|
onConnectionClosed(event) {
|
|
179
172
|
Log_1.gLog.info({ key: "mongo onConnectionClosed", event });
|
|
180
|
-
this._inited = false;
|
|
181
|
-
this.init(this._mongocfg);
|
|
182
173
|
}
|
|
183
174
|
close(force = false) {
|
|
184
175
|
this._mongoClient.close(force);
|
|
@@ -186,9 +177,21 @@ class MongoExt {
|
|
|
186
177
|
registerInitCb(cb) {
|
|
187
178
|
this._init_cbs.push(cb);
|
|
188
179
|
}
|
|
189
|
-
|
|
180
|
+
onOpen() {
|
|
190
181
|
this._mongo_init_succ = true;
|
|
191
|
-
Log_1.gLog.info("mongo has
|
|
182
|
+
Log_1.gLog.info("mongo has opened!");
|
|
183
|
+
this._mongoDb = this._mongoClient.db(this._mongocfg.database);
|
|
184
|
+
for (let i = 0; i < this._init_cbs.length; ++i) {
|
|
185
|
+
this._init_cbs[i]();
|
|
186
|
+
}
|
|
187
|
+
this._init_cbs = [];
|
|
188
|
+
}
|
|
189
|
+
onClose() {
|
|
190
|
+
this._mongo_init_succ = false;
|
|
191
|
+
Log_1.gLog.info("mongo has closed!");
|
|
192
|
+
this._mongoDb = null;
|
|
193
|
+
this._inited = false;
|
|
194
|
+
this.init(this._mongocfg);
|
|
192
195
|
}
|
|
193
196
|
/**
|
|
194
197
|
* 获取自增长id
|
|
@@ -63,7 +63,8 @@ export declare class MongoExt {
|
|
|
63
63
|
onConnectionClosed(event: mongo.ConnectionClosedEvent): void;
|
|
64
64
|
close(force?: boolean): void;
|
|
65
65
|
registerInitCb(cb: Function): void;
|
|
66
|
-
|
|
66
|
+
onOpen(): void;
|
|
67
|
+
onClose(): void;
|
|
67
68
|
/**
|
|
68
69
|
* 获取自增长id
|
|
69
70
|
* @param key
|