badmfck-api-server 1.2.2 → 1.2.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.
| @@ -37,6 +37,7 @@ export declare class MysqlService extends BaseService { | |
| 37 37 | 
             
                pool: Pool | null;
         | 
| 38 38 | 
             
                options: MysqlServiceOptions;
         | 
| 39 39 | 
             
                serviceStarted: boolean;
         | 
| 40 | 
            +
                timeoutID: any;
         | 
| 40 41 | 
             
                queries: never[];
         | 
| 41 42 | 
             
                constructor(options: MysqlServiceOptions);
         | 
| 42 43 | 
             
                static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
         | 
| @@ -16,6 +16,7 @@ class MysqlService extends BaseService_1.BaseService { | |
| 16 16 | 
             
                pool = null;
         | 
| 17 17 | 
             
                options;
         | 
| 18 18 | 
             
                serviceStarted = false;
         | 
| 19 | 
            +
                timeoutID;
         | 
| 19 20 | 
             
                queries = [];
         | 
| 20 21 | 
             
                constructor(options) {
         | 
| 21 22 | 
             
                    super("mysql");
         | 
| @@ -44,7 +45,9 @@ class MysqlService extends BaseService_1.BaseService { | |
| 44 45 | 
             
                    if (!ok) {
         | 
| 45 46 | 
             
                        if (this.options.onLog)
         | 
| 46 47 | 
             
                            this.options.onLog(2, "Mysql server not connected, retrying in 3 sec");
         | 
| 47 | 
            -
                         | 
| 48 | 
            +
                        if (this.timeoutID)
         | 
| 49 | 
            +
                            clearTimeout(this.timeoutID);
         | 
| 50 | 
            +
                        this.timeoutID = setTimeout(() => { this.recreatePool(); }, 3000);
         | 
| 48 51 | 
             
                    }
         | 
| 49 52 | 
             
                    else {
         | 
| 50 53 | 
             
                        this.serviceStarted = true;
         | 
| @@ -136,10 +139,6 @@ class MysqlService extends BaseService_1.BaseService { | |
| 136 139 | 
             
                            });
         | 
| 137 140 | 
             
                            return;
         | 
| 138 141 | 
             
                        }
         | 
| 139 | 
            -
                        this.pool.on("error", (evt) => {
         | 
| 140 | 
            -
                            if (this.options.onLog)
         | 
| 141 | 
            -
                                this.options.onLog(2, `${evt}`);
         | 
| 142 | 
            -
                        });
         | 
| 143 142 | 
             
                        this.pool.getConnection((err, conn) => {
         | 
| 144 143 | 
             
                            if (err) {
         | 
| 145 144 | 
             
                                if (this.options.onLog)
         | 
| @@ -250,6 +249,19 @@ class MysqlService extends BaseService_1.BaseService { | |
| 250 249 | 
             
                    if (this.options.onLog)
         | 
| 251 250 | 
             
                        this.options.onLog(1, "Connecting to mysql: \n HOST: " + this.options.host + '\n USER:' + this.options.user + '\n PORT:' + this.options.port);
         | 
| 252 251 | 
             
                    let err = false;
         | 
| 252 | 
            +
                    if (this.pool) {
         | 
| 253 | 
            +
                        try {
         | 
| 254 | 
            +
                            this.pool.removeAllListeners();
         | 
| 255 | 
            +
                            this.pool.end(err => {
         | 
| 256 | 
            +
                                if (err && this.options.onLog)
         | 
| 257 | 
            +
                                    this.options.onLog(2, err);
         | 
| 258 | 
            +
                            });
         | 
| 259 | 
            +
                        }
         | 
| 260 | 
            +
                        catch (e) {
         | 
| 261 | 
            +
                            if (this.options.onLog)
         | 
| 262 | 
            +
                                this.options.onLog(2, e);
         | 
| 263 | 
            +
                        }
         | 
| 264 | 
            +
                    }
         | 
| 253 265 | 
             
                    try {
         | 
| 254 266 | 
             
                        this.pool = mysql_1.default.createPool({
         | 
| 255 267 | 
             
                            connectionLimit: this.options.connectionLimit,
         | 
| @@ -266,7 +278,12 @@ class MysqlService extends BaseService_1.BaseService { | |
| 266 278 | 
             
                            this.options.onLog(2, "Can't connect to MYSQL!");
         | 
| 267 279 | 
             
                        err = true;
         | 
| 268 280 | 
             
                    }
         | 
| 269 | 
            -
                     | 
| 281 | 
            +
                    if (!err && this.pool) {
         | 
| 282 | 
            +
                        this.pool.on("error", (evt) => {
         | 
| 283 | 
            +
                            if (this.options.onLog)
         | 
| 284 | 
            +
                                this.options.onLog(2, `${evt}`);
         | 
| 285 | 
            +
                        });
         | 
| 286 | 
            +
                    }
         | 
| 270 287 | 
             
                    return new Promise((res, rej) => {
         | 
| 271 288 | 
             
                        if (err) {
         | 
| 272 289 | 
             
                            res(false);
         |