badmfck-api-server 2.3.1 → 2.3.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.
@@ -83,7 +83,7 @@ async function Initializer(services) {
83
83
  exports.Initializer = Initializer;
84
84
  class APIService extends BaseService_1.BaseService {
85
85
  static nextLogID = 0;
86
- version = "2.3.1";
86
+ version = "2.3.2";
87
87
  options;
88
88
  monitor;
89
89
  monitorIndexFile;
@@ -25,6 +25,7 @@ export interface MysqlServiceOptions {
25
25
  transactionFailReport?: (trx: ITransaction, message: string) => void;
26
26
  transactionFailReportDir?: string;
27
27
  debug?: boolean;
28
+ naxTransactionWaitTime?: number;
28
29
  migrations?: {
29
30
  dir: string;
30
31
  callback: () => void;
@@ -52,9 +52,9 @@ class MysqlService extends BaseService_1.BaseService {
52
52
  timeoutID;
53
53
  debug = false;
54
54
  queries = [];
55
- static nextTransactionID = 0;
55
+ static nextTransactionID = 1;
56
56
  transactions = [];
57
- maxTransactionWaitTime = 1000 * 60 * 2;
57
+ maxTransactionWaitTime = 1000 * 60 * 1;
58
58
  failReportFileStream = null;
59
59
  failReportFileStreamName = null;
60
60
  failReportLastAccessTime = 0;
@@ -71,8 +71,11 @@ class MysqlService extends BaseService_1.BaseService {
71
71
  this.options.password = decrypt(this.options.password.substring(1)) ?? this.options.password;
72
72
  if (this.options.debug)
73
73
  this.debug = true;
74
+ if (this.options.naxTransactionWaitTime)
75
+ this.maxTransactionWaitTime = this.options.naxTransactionWaitTime;
74
76
  setInterval(() => {
75
77
  const now = Date.now();
78
+ const count = this.transactions.length;
76
79
  this.transactions = this.transactions.filter(async (i) => {
77
80
  if (now - i.timestamp < this.maxTransactionWaitTime)
78
81
  return true;
@@ -81,12 +84,16 @@ class MysqlService extends BaseService_1.BaseService {
81
84
  i.conn.removeAllListeners();
82
85
  await i.conn.rollback();
83
86
  i.conn.release();
87
+ this.storeTransactionAsProblem(i, "Timeout");
84
88
  }
85
89
  catch (e) {
86
90
  (0, LogService_1.logError)("Can't release transaction", e);
91
+ this.storeTransactionAsProblem(i, "Timeout, cant,release");
87
92
  }
88
93
  return false;
89
94
  });
95
+ if (this.debug)
96
+ console.log("Removed: ", count - this.transactions.length);
90
97
  }, 1000 * 30);
91
98
  setInterval(() => {
92
99
  if (!this.failReportFileStream)
@@ -145,6 +152,12 @@ class MysqlService extends BaseService_1.BaseService {
145
152
  const conn = await this.pool?.getConnection();
146
153
  if (!conn)
147
154
  return { code: "NO_POOL", errno: 100000, fatal: true, sql: "", name: "NO_POOL", message: "Mysql pool not created" };
155
+ for (let i of this.transactions) {
156
+ if (i.conn === conn) {
157
+ (0, LogService_1.logInfo)("Your connection is in transaction");
158
+ return { code: "CONN_IN_TRX", errno: 100005, fatal: true, sql: "", name: "CONN_IN_TRX", message: "Connection is in transaction" };
159
+ }
160
+ }
148
161
  const tid = MysqlService.nextTransactionID++;
149
162
  if (this.debug)
150
163
  console.log("Begin transaction with id ", tid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",