badmfck-api-server 2.3.6 → 2.3.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -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,13 +155,12 @@ 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.
|
159
|
-
const res = await conn.query("SET autocommit=0");
|
158
|
+
await conn.query("START TRANSACTION");
|
160
159
|
if (this.debug)
|
161
|
-
console.log("Transaction started
|
160
|
+
console.log("Transaction started");
|
162
161
|
}
|
163
162
|
catch (e) {
|
164
|
-
this.rollbackTransaction({ id: tid, conn: conn, timestamp: Date.now(), queries: [{ sql: "
|
163
|
+
this.rollbackTransaction({ id: tid, conn: conn, timestamp: Date.now(), queries: [{ sql: "START TRANSACTION", status: "error" }] });
|
165
164
|
return this.createMysqlQueryError(e);
|
166
165
|
}
|
167
166
|
this.transactions.push({
|
@@ -218,7 +217,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
218
217
|
message: "Transaction not found"
|
219
218
|
};
|
220
219
|
}
|
221
|
-
this.rollbackTransaction(trx);
|
220
|
+
await this.rollbackTransaction(trx);
|
222
221
|
return null;
|
223
222
|
};
|
224
223
|
exports.REQ_MYSQL_TCOMMIT.listener = async (tid) => {
|
@@ -238,18 +237,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
238
237
|
this.transactions = this.transactions.filter(i => i.id !== tid);
|
239
238
|
if (this.debug)
|
240
239
|
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;
|
240
|
+
const err = await this.commit(trx);
|
241
|
+
return err;
|
253
242
|
};
|
254
243
|
exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
|
255
244
|
if (!this.pool)
|
@@ -266,8 +255,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
266
255
|
};
|
267
256
|
let income = [];
|
268
257
|
try {
|
269
|
-
await conn.
|
270
|
-
await conn.query("SET autocommit=0");
|
258
|
+
await conn.query("START TRANSACTION");
|
271
259
|
}
|
272
260
|
catch (e) {
|
273
261
|
const err = this.createMysqlQueryError(e);
|
@@ -293,21 +281,28 @@ class MysqlService extends BaseService_1.BaseService {
|
|
293
281
|
return { error: err, data: null };
|
294
282
|
}
|
295
283
|
}
|
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 };
|
284
|
+
const err = await this.commit(trx);
|
285
|
+
return { error: err, data: income };
|
305
286
|
};
|
306
287
|
}
|
288
|
+
async commit(trx) {
|
289
|
+
try {
|
290
|
+
await trx.conn.commit();
|
291
|
+
trx.conn.removeAllListeners();
|
292
|
+
trx.conn.release();
|
293
|
+
}
|
294
|
+
catch (e) {
|
295
|
+
await this.rollbackTransaction(trx);
|
296
|
+
return this.createMysqlQueryError(e);
|
297
|
+
}
|
298
|
+
return null;
|
299
|
+
}
|
307
300
|
async rollbackTransaction(trx, donNotRemove) {
|
301
|
+
let err = null;
|
308
302
|
try {
|
309
303
|
console.log("Rollback started", trx.conn);
|
310
304
|
await trx.conn.rollback();
|
305
|
+
await trx.conn.commit();
|
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");
|