badmfck-api-server 2.3.5 → 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,12 +218,7 @@ class MysqlService extends BaseService_1.BaseService { | |
| 218 218 | 
             
                                message: "Transaction not found"
         | 
| 219 219 | 
             
                            };
         | 
| 220 220 | 
             
                        }
         | 
| 221 | 
            -
                         | 
| 222 | 
            -
                            console.log("Rollback transaction:", trx);
         | 
| 223 | 
            -
                        this.transactions = this.transactions.filter(i => i.id !== tid);
         | 
| 224 | 
            -
                        if (this.debug)
         | 
| 225 | 
            -
                            console.log("Transaction pool:", this.transactions);
         | 
| 226 | 
            -
                        this.rollbackTransaction(trx);
         | 
| 221 | 
            +
                        await this.rollbackTransaction(trx);
         | 
| 227 222 | 
             
                        return null;
         | 
| 228 223 | 
             
                    };
         | 
| 229 224 | 
             
                    exports.REQ_MYSQL_TCOMMIT.listener = async (tid) => {
         | 
| @@ -243,18 +238,8 @@ class MysqlService extends BaseService_1.BaseService { | |
| 243 238 | 
             
                        this.transactions = this.transactions.filter(i => i.id !== tid);
         | 
| 244 239 | 
             
                        if (this.debug)
         | 
| 245 240 | 
             
                            console.log("Transaction pool:", this.transactions);
         | 
| 246 | 
            -
                         | 
| 247 | 
            -
             | 
| 248 | 
            -
                            trx.conn.removeAllListeners();
         | 
| 249 | 
            -
                            trx.conn.release();
         | 
| 250 | 
            -
                            if (this.debug)
         | 
| 251 | 
            -
                                console.log("Commit completed:");
         | 
| 252 | 
            -
                        }
         | 
| 253 | 
            -
                        catch (e) {
         | 
| 254 | 
            -
                            this.rollbackTransaction(trx);
         | 
| 255 | 
            -
                            return this.createMysqlQueryError(e);
         | 
| 256 | 
            -
                        }
         | 
| 257 | 
            -
                        return null;
         | 
| 241 | 
            +
                        const err = await this.commit(trx);
         | 
| 242 | 
            +
                        return err;
         | 
| 258 243 | 
             
                    };
         | 
| 259 244 | 
             
                    exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
         | 
| 260 245 | 
             
                        if (!this.pool)
         | 
| @@ -271,8 +256,7 @@ class MysqlService extends BaseService_1.BaseService { | |
| 271 256 | 
             
                        };
         | 
| 272 257 | 
             
                        let income = [];
         | 
| 273 258 | 
             
                        try {
         | 
| 274 | 
            -
                            await conn. | 
| 275 | 
            -
                            await conn.query("SET autocommit=0");
         | 
| 259 | 
            +
                            await conn.query("START TRANSACTION; SET autocommit=0");
         | 
| 276 260 | 
             
                        }
         | 
| 277 261 | 
             
                        catch (e) {
         | 
| 278 262 | 
             
                            const err = this.createMysqlQueryError(e);
         | 
| @@ -298,21 +282,27 @@ class MysqlService extends BaseService_1.BaseService { | |
| 298 282 | 
             
                                return { error: err, data: null };
         | 
| 299 283 | 
             
                            }
         | 
| 300 284 | 
             
                        }
         | 
| 301 | 
            -
                         | 
| 302 | 
            -
             | 
| 303 | 
            -
                        }
         | 
| 304 | 
            -
                        catch (e) {
         | 
| 305 | 
            -
                            await this.rollbackTransaction(trx);
         | 
| 306 | 
            -
                            const err = this.createMysqlQueryError(e);
         | 
| 307 | 
            -
                            return { error: err, data: null };
         | 
| 308 | 
            -
                        }
         | 
| 309 | 
            -
                        return { error: null, data: income };
         | 
| 285 | 
            +
                        const err = await this.commit(trx);
         | 
| 286 | 
            +
                        return { error: err, data: income };
         | 
| 310 287 | 
             
                    };
         | 
| 311 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 | 
            +
                }
         | 
| 312 301 | 
             
                async rollbackTransaction(trx, donNotRemove) {
         | 
| 302 | 
            +
                    let err = null;
         | 
| 313 303 | 
             
                    try {
         | 
| 314 304 | 
             
                        console.log("Rollback started", trx.conn);
         | 
| 315 | 
            -
                        await trx.conn. | 
| 305 | 
            +
                        await trx.conn.query("ROLLBACK");
         | 
| 316 306 | 
             
                        trx.conn.removeAllListeners();
         | 
| 317 307 | 
             
                        trx.conn.release();
         | 
| 318 308 | 
             
                        if (!donNotRemove)
         | 
| @@ -322,8 +312,10 @@ class MysqlService extends BaseService_1.BaseService { | |
| 322 312 | 
             
                    }
         | 
| 323 313 | 
             
                    catch (e) {
         | 
| 324 314 | 
             
                        (0, LogService_1.logCrit)("${MysqlService.js}", "Can't rollback transaction", trx);
         | 
| 315 | 
            +
                        err = this.createMysqlQueryError(e);
         | 
| 325 316 | 
             
                    }
         | 
| 326 317 | 
             
                    this.storeTransactionAsProblem(trx, "rollback");
         | 
| 318 | 
            +
                    return err;
         | 
| 327 319 | 
             
                }
         | 
| 328 320 | 
             
                async finishApp() {
         | 
| 329 321 | 
             
                    console.log("Finishing mysql service");
         | 
| @@ -364,7 +356,7 @@ class MysqlService extends BaseService_1.BaseService { | |
| 364 356 | 
             
                            console.log("Store transaction fail report: ", file, trx, message);
         | 
| 365 357 | 
             
                        if (!this.failReportFileStream)
         | 
| 366 358 | 
             
                            this.failReportFileStream = fs_1.default.createWriteStream(file, { flags: 'a' });
         | 
| 367 | 
            -
                        this.failReportFileStream.write(JSON.stringify({ queries: trx.queries, time: trx.timestamp, date, message }) + "\n{ | 
| 359 | 
            +
                        this.failReportFileStream.write(JSON.stringify({ queries: trx.queries, time: trx.timestamp, date, message }) + "\n}EOB{\n", err => {
         | 
| 368 360 | 
             
                            if (err)
         | 
| 369 361 | 
             
                                (0, LogService_1.logCrit)("${MysqlService.js}", "Can't write to transaction fail report file");
         | 
| 370 362 | 
             
                            else
         |