cgserver 13.1.2 → 13.1.3

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.
package/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # 版本更新日志
2
+ ## v13+
3
+ - 主要是mongo更换为mongoose,老项目不要升级
4
+
2
5
  ## v12.3.6
3
6
  - cache的过期时间修改
4
7
  ## v12.3.5
@@ -97,6 +97,10 @@ class MongoExt {
97
97
  _init_cbs = [];
98
98
  _mongo_init_succ = false;
99
99
  _inited = false;
100
+ _cur_connecting_count = 0;
101
+ get curConnectingCount() {
102
+ return this._cur_connecting_count;
103
+ }
100
104
  get isValid() {
101
105
  return this._inited;
102
106
  }
@@ -112,14 +116,22 @@ class MongoExt {
112
116
  this._mongocfg = cfg;
113
117
  this._inited = true;
114
118
  Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
119
+ mongoose_1.default.connection.on("connected", this.onClose.bind(this));
115
120
  mongoose_1.default.connection.on("disconnected", this.onClose.bind(this));
116
121
  mongoose_1.default.connection.on("open", this.onOpen.bind(this));
122
+ mongoose_1.default.connection.on("close", this.onClose.bind(this));
117
123
  this._mongocfg.options.dbName = this._mongocfg.database;
118
124
  await mongoose_1.default.connect("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
119
125
  mongoose_1.default.connection.useDb(this._mongocfg.database);
120
126
  console.log("mongo connect success! db=" + this._mongocfg.database);
121
127
  return true;
122
128
  }
129
+ onConnect() {
130
+ this._cur_connecting_count++;
131
+ }
132
+ onDisconnect() {
133
+ this._cur_connecting_count--;
134
+ }
123
135
  close(force = false) {
124
136
  mongoose_1.default.connection.close(force);
125
137
  }
@@ -140,6 +152,12 @@ class MongoExt {
140
152
  this._inited = false;
141
153
  //this.init(this._mongocfg)
142
154
  }
155
+ async getConnectionStats() {
156
+ const stats = await mongoose_1.default.connection.db.admin().serverStatus();
157
+ let current = stats.connections.current;
158
+ let available = stats.connections.available;
159
+ return { current, available };
160
+ }
143
161
  onError(err) {
144
162
  Log_1.gLog.error(err);
145
163
  }
@@ -49,13 +49,21 @@ export declare class MongoExt {
49
49
  protected _init_cbs: any[];
50
50
  protected _mongo_init_succ: boolean;
51
51
  protected _inited: boolean;
52
+ protected _cur_connecting_count: number;
53
+ get curConnectingCount(): number;
52
54
  get isValid(): boolean;
53
55
  constructor();
54
56
  init(cfg: MongoConfig): Promise<boolean>;
57
+ onConnect(): void;
58
+ onDisconnect(): void;
55
59
  close(force?: boolean): void;
56
60
  registerInitCb(cb: Function): void;
57
61
  onOpen(): void;
58
62
  onClose(): void;
63
+ getConnectionStats(): Promise<{
64
+ current: any;
65
+ available: any;
66
+ }>;
59
67
  onError(err: Error): void;
60
68
  /**
61
69
  * 获取自增长id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "13.1.2",
3
+ "version": "13.1.3",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",