cgserver 12.2.1 → 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.
|
@@ -154,6 +154,8 @@ class MongoExt {
|
|
|
154
154
|
this._inited = true;
|
|
155
155
|
Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
|
|
156
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));
|
|
157
159
|
this._mongoClient.on("connectionCreated", this.onConnectionCreated.bind(this));
|
|
158
160
|
this._mongoClient.on("connectionReady", this.onConnectionReady.bind(this));
|
|
159
161
|
this._mongoClient.on("connectionClosed", this.onConnectionClosed.bind(this));
|
|
@@ -165,18 +167,9 @@ class MongoExt {
|
|
|
165
167
|
}
|
|
166
168
|
onConnectionReady(event) {
|
|
167
169
|
Log_1.gLog.info({ key: "mongo onConnectionReady", event });
|
|
168
|
-
this.onConnect();
|
|
169
|
-
this._mongoDb = this._mongoClient.db(this._mongocfg.database);
|
|
170
|
-
for (let i = 0; i < this._init_cbs.length; ++i) {
|
|
171
|
-
this._init_cbs[i]();
|
|
172
|
-
}
|
|
173
|
-
this._init_cbs = [];
|
|
174
170
|
}
|
|
175
171
|
onConnectionClosed(event) {
|
|
176
172
|
Log_1.gLog.info({ key: "mongo onConnectionClosed", event });
|
|
177
|
-
this._inited = false;
|
|
178
|
-
this._mongoDb = null;
|
|
179
|
-
this.init(this._mongocfg);
|
|
180
173
|
}
|
|
181
174
|
close(force = false) {
|
|
182
175
|
this._mongoClient.close(force);
|
|
@@ -184,9 +177,21 @@ class MongoExt {
|
|
|
184
177
|
registerInitCb(cb) {
|
|
185
178
|
this._init_cbs.push(cb);
|
|
186
179
|
}
|
|
187
|
-
|
|
180
|
+
onOpen() {
|
|
188
181
|
this._mongo_init_succ = true;
|
|
189
|
-
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);
|
|
190
195
|
}
|
|
191
196
|
/**
|
|
192
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
|