@flutry/sequelize 0.0.5 → 0.0.6

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.
@@ -2,6 +2,9 @@ import { Sequelize } from 'sequelize';
2
2
  export declare class Flutry_Connect {
3
3
  static sequelize: Sequelize;
4
4
  private readonly functions;
5
+ private retryCount;
6
+ private maxRetries;
7
+ private retryDelay;
5
8
  constructor();
6
9
  private init;
7
10
  private connect;
@@ -8,6 +8,9 @@ const models_1 = require("../models/models");
8
8
  class Flutry_Connect {
9
9
  constructor() {
10
10
  this.functions = new function_1.Functions();
11
+ this.retryCount = 0;
12
+ this.maxRetries = 5; // Maximum retry attempts
13
+ this.retryDelay = 5000; // 5 seconds
11
14
  this.init = async () => {
12
15
  if (await this.functions.DBConfigVerify()) {
13
16
  this.connect();
@@ -24,9 +27,21 @@ class Flutry_Connect {
24
27
  await Flutry_Connect.sequelize.authenticate();
25
28
  //Flutry_Sequelize.logger.info('Connection has been established successfully'); //! This line commented for now
26
29
  await new models_1.Flutry_Models();
30
+ this.retryCount = 0; // Reset retry count on successful connection
27
31
  }
28
32
  catch (error) {
29
- main_1.Flutry_Sequelize.logger.error('Unebale to connect to the database');
33
+ main_1.Flutry_Sequelize.logger.error(`Unable to connect to the database. Attempt ${this.retryCount + 1}/${this.maxRetries}`);
34
+ if (this.retryCount < this.maxRetries) {
35
+ this.retryCount++;
36
+ main_1.Flutry_Sequelize.logger.info(`Retrying connection in ${this.retryDelay / 1000} seconds...`);
37
+ setTimeout(() => {
38
+ this.connect();
39
+ }, this.retryDelay);
40
+ }
41
+ else {
42
+ main_1.Flutry_Sequelize.logger.error('Maximum retry attempts reached. Unable to connect to database.');
43
+ this.retryCount = 0; // Reset for potential future attempts
44
+ }
30
45
  }
31
46
  };
32
47
  this.init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flutry/sequelize",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [