badmfck-api-server 2.3.6 → 2.3.7
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.
|
@@ -95,7 +95,8 @@ export declare class MysqlService extends BaseService {
|
|
|
95
95
|
constructor(options: MysqlServiceOptions);
|
|
96
96
|
static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
|
|
97
97
|
init(): Promise<void>;
|
|
98
|
-
|
|
98
|
+
commit(trx: ITransaction): Promise<MysqlError | null>;
|
|
99
|
+
rollbackTransaction(trx: ITransaction, donNotRemove?: boolean): Promise<MysqlError | null>;
|
|
99
100
|
finishApp(): Promise<void>;
|
|
100
101
|
storeTransactionAsProblem(trx: ITransaction, message: string): Promise<void>;
|
|
101
102
|
recreatePool(): Promise<boolean>;
|
|
@@ -155,7 +155,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
155
155
|
if (this.debug)
|
|
156
156
|
console.log("Begin transaction with id ", tid);
|
|
157
157
|
try {
|
|
158
|
-
await conn.
|
|
158
|
+
await conn.query("START TRANSACTION");
|
|
159
159
|
const res = await conn.query("SET autocommit=0");
|
|
160
160
|
if (this.debug)
|
|
161
161
|
console.log("Transaction started, SET autocommit=0 ", tid, res);
|
|
@@ -218,7 +218,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
218
218
|
message: "Transaction not found"
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
|
-
this.rollbackTransaction(trx);
|
|
221
|
+
await this.rollbackTransaction(trx);
|
|
222
222
|
return null;
|
|
223
223
|
};
|
|
224
224
|
exports.REQ_MYSQL_TCOMMIT.listener = async (tid) => {
|
|
@@ -238,18 +238,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
238
238
|
this.transactions = this.transactions.filter(i => i.id !== tid);
|
|
239
239
|
if (this.debug)
|
|
240
240
|
console.log("Transaction pool:", this.transactions);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
trx.conn.removeAllListeners();
|
|
244
|
-
trx.conn.release();
|
|
245
|
-
if (this.debug)
|
|
246
|
-
console.log("Commit completed:");
|
|
247
|
-
}
|
|
248
|
-
catch (e) {
|
|
249
|
-
this.rollbackTransaction(trx);
|
|
250
|
-
return this.createMysqlQueryError(e);
|
|
251
|
-
}
|
|
252
|
-
return null;
|
|
241
|
+
const err = await this.commit(trx);
|
|
242
|
+
return err;
|
|
253
243
|
};
|
|
254
244
|
exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
|
|
255
245
|
if (!this.pool)
|
|
@@ -266,8 +256,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
266
256
|
};
|
|
267
257
|
let income = [];
|
|
268
258
|
try {
|
|
269
|
-
await conn.
|
|
270
|
-
await conn.query("SET autocommit=0");
|
|
259
|
+
await conn.query("START TRANSACTION; SET autocommit=0");
|
|
271
260
|
}
|
|
272
261
|
catch (e) {
|
|
273
262
|
const err = this.createMysqlQueryError(e);
|
|
@@ -293,21 +282,27 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
293
282
|
return { error: err, data: null };
|
|
294
283
|
}
|
|
295
284
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
catch (e) {
|
|
300
|
-
await this.rollbackTransaction(trx);
|
|
301
|
-
const err = this.createMysqlQueryError(e);
|
|
302
|
-
return { error: err, data: null };
|
|
303
|
-
}
|
|
304
|
-
return { error: null, data: income };
|
|
285
|
+
const err = await this.commit(trx);
|
|
286
|
+
return { error: err, data: income };
|
|
305
287
|
};
|
|
306
288
|
}
|
|
289
|
+
async commit(trx) {
|
|
290
|
+
try {
|
|
291
|
+
await trx.conn.query("COMMIT");
|
|
292
|
+
trx.conn.removeAllListeners();
|
|
293
|
+
trx.conn.release();
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
await this.rollbackTransaction(trx);
|
|
297
|
+
return this.createMysqlQueryError(e);
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
307
301
|
async rollbackTransaction(trx, donNotRemove) {
|
|
302
|
+
let err = null;
|
|
308
303
|
try {
|
|
309
304
|
console.log("Rollback started", trx.conn);
|
|
310
|
-
await trx.conn.
|
|
305
|
+
await trx.conn.query("ROLLBACK");
|
|
311
306
|
trx.conn.removeAllListeners();
|
|
312
307
|
trx.conn.release();
|
|
313
308
|
if (!donNotRemove)
|
|
@@ -317,8 +312,10 @@ class MysqlService extends BaseService_1.BaseService {
|
|
|
317
312
|
}
|
|
318
313
|
catch (e) {
|
|
319
314
|
(0, LogService_1.logCrit)("${MysqlService.js}", "Can't rollback transaction", trx);
|
|
315
|
+
err = this.createMysqlQueryError(e);
|
|
320
316
|
}
|
|
321
317
|
this.storeTransactionAsProblem(trx, "rollback");
|
|
318
|
+
return err;
|
|
322
319
|
}
|
|
323
320
|
async finishApp() {
|
|
324
321
|
console.log("Finishing mysql service");
|