badmfck-api-server 2.3.2 → 2.3.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.
@@ -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.2";
86
+ version = "2.3.3";
87
87
  options;
88
88
  monitor;
89
89
  monitorIndexFile;
@@ -76,22 +76,18 @@ class MysqlService extends BaseService_1.BaseService {
76
76
  setInterval(() => {
77
77
  const now = Date.now();
78
78
  const count = this.transactions.length;
79
- this.transactions = this.transactions.filter(async (i) => {
80
- if (now - i.timestamp < this.maxTransactionWaitTime)
81
- return true;
82
- try {
79
+ const removedIDs = [];
80
+ for (let i of this.transactions) {
81
+ if (now - i.timestamp > this.maxTransactionWaitTime) {
83
82
  (0, LogService_1.logError)("Release transaction connection due to timeout");
84
83
  i.conn.removeAllListeners();
85
- await i.conn.rollback();
84
+ i.conn.rollback();
86
85
  i.conn.release();
87
86
  this.storeTransactionAsProblem(i, "Timeout");
87
+ removedIDs.push(i.id);
88
88
  }
89
- catch (e) {
90
- (0, LogService_1.logError)("Can't release transaction", e);
91
- this.storeTransactionAsProblem(i, "Timeout, cant,release");
92
- }
93
- return false;
94
- });
89
+ }
90
+ this.transactions = this.transactions.filter(i => !removedIDs.includes(i.id));
95
91
  if (this.debug)
96
92
  console.log("Removed: ", count - this.transactions.length);
97
93
  }, 1000 * 30);
@@ -410,7 +406,9 @@ class MysqlService extends BaseService_1.BaseService {
410
406
  }
411
407
  if (this.debug)
412
408
  console.log("Store transaction fail report: ", file, trx, message);
413
- this.failReportFileStream?.write(JSON.stringify({ trx, date, message }) + "\n{'s':'&$5__1AzZa'}\n", err => {
409
+ if (!this.failReportFileStream)
410
+ this.failReportFileStream = fs_1.default.createWriteStream(file, { flags: 'a' });
411
+ this.failReportFileStream.write(JSON.stringify({ trx, date, message }) + "\n{'s':'&$5__1AzZa'}\n", err => {
414
412
  if (err)
415
413
  (0, LogService_1.logCrit)("${MysqlService.js}", "Can't write to transaction fail report file");
416
414
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",