@seidor-cloud-produtos/orbit-backend-lib 0.0.80 → 0.0.83

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.
@@ -14,7 +14,6 @@ class AmqpQueue {
14
14
  this.vHost = vHost;
15
15
  await this.treatReconnection(vHost);
16
16
  if (process.env.NODE_ENV !== 'test') {
17
- console.log('\n');
18
17
  console.log(`🐝 Queue connected on vHost: ${this.vHost}`);
19
18
  }
20
19
  return this;
@@ -129,9 +128,8 @@ class AmqpQueue {
129
128
  async treatReconnection(vHost) {
130
129
  this.connection.removeAllListeners('close');
131
130
  this.connection.on('close', async () => {
132
- console.log('\n');
133
131
  console.log('⛔ Connection Closed!!');
134
- console.log(`⟳ Try connection to the vHost: ${vHost}`);
132
+ console.log(`🔄 Try connection to the vHost: ${vHost}`);
135
133
  const interval = setInterval(async () => {
136
134
  try {
137
135
  AmqpQueue.instance = await this.connect(vHost);
@@ -140,7 +138,7 @@ class AmqpQueue {
140
138
  await this.publishMessagesOfMemory();
141
139
  clearInterval(interval);
142
140
  } catch {
143
- console.log(`⟳ Trying to connection to the vHost: ${vHost}`);
141
+ console.log(`🔄 Trying to connection to the vHost: ${vHost}`);
144
142
  }
145
143
  }, 5000);
146
144
  });
@@ -0,0 +1,8 @@
1
+ export default class ForkWorker {
2
+ private attemptCount;
3
+ private maxAttempts;
4
+ private retryDelay;
5
+ private workerPath;
6
+ constructor(workerPath: string);
7
+ fWorker(): void;
8
+ }
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const child_process_1 = require('child_process');
4
+ class ForkWorker {
5
+ constructor(workerPath) {
6
+ this.attemptCount = 0;
7
+ this.maxAttempts = 5;
8
+ this.retryDelay = 3000;
9
+ this.workerPath = workerPath;
10
+ }
11
+ fWorker() {
12
+ const child = (0, child_process_1.fork)(this.workerPath);
13
+ child.on('error', err => {
14
+ console.log('\n');
15
+ console.error(`⛔ Child process ${child.pid} error :`, err);
16
+ });
17
+ child.on('exit', code => {
18
+ console.log('\n');
19
+ console.log(`⛔ Worker process ${child.pid} exited with code ${code}`);
20
+ if (code !== 0 && this.attemptCount < this.maxAttempts) {
21
+ this.attemptCount++;
22
+ console.log('\n');
23
+ console.log(
24
+ `🔄 Restarting worker process... Attempt ${this.attemptCount} of ${this.maxAttempts}`,
25
+ );
26
+ setTimeout(this.fWorker.bind(this), this.retryDelay);
27
+ } else if (this.attemptCount >= this.maxAttempts) {
28
+ console.log('\n');
29
+ console.error(
30
+ `⛔ Max restart attempts reached. Not restarting worker process ${child.pid}. Container restart required!`,
31
+ );
32
+ }
33
+ });
34
+ }
35
+ }
36
+ exports.default = ForkWorker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "0.0.80",
3
+ "version": "0.0.83",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -90,4 +90,4 @@
90
90
  "tslib": "2.6.2",
91
91
  "zod": "3.23.8"
92
92
  }
93
- }
93
+ }