@codefresh-io/service-base 6.0.1-beta → 6.0.2-beta

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.
package/infra/index.js CHANGED
@@ -119,8 +119,10 @@ class Microservice {
119
119
  logger.info(`Starting shutdown... Timeout: ${gracePeriod}`);
120
120
  const promises = [];
121
121
  if (enabledComponents.includes('mongo')) {
122
- logger.info('About to stop mongo');
123
- promises.push(mongo.stop.bind(mongo));
122
+ promises.push(async () => {
123
+ logger.info('About to stop mongo');
124
+ await mongo.stop();
125
+ });
124
126
  }
125
127
  if (enabledComponents.includes('eventbus')) {
126
128
  logger.info('About to stop eventbus');
package/infra/mongo.js CHANGED
@@ -9,32 +9,40 @@ class Mongo {
9
9
 
10
10
  /**
11
11
  * starts the connection to mongo
12
- * @returns {Promise<void>}
13
12
  */
14
13
  async init(config) {
15
14
  const clientSettings = { ...config.mongo.options };
16
-
17
15
  const logger = require('cf-logs').Logger('codefresh:infra:mongo'); // eslint-disable-line
18
16
  this.logger = logger;
19
17
 
20
18
  const { uri } = config.mongo;
19
+ logger.info(`Mongo db uri ${uri}`);
21
20
  const dbName = config.mongo.dbName || getDbNameFromUri(uri);
22
- const client = await MongoClient.connect(uri, clientSettings);
21
+ const client = new MongoClient(uri, clientSettings);
22
+ logger.info(`Mongo db name ${dbName}`);
23
+
24
+ try {
25
+ await client.connect();
26
+ logger.info('Mongo driver connected');
27
+ } catch (error) {
28
+ logger.error('Error connecting to MongoDB:', error);
29
+ throw error; // Re-throw the error to propagate it
30
+ }
31
+
23
32
  this.client = client;
24
- this.db = client.db(dbName);
25
- logger.info('Mongo driver connected');
33
+ this.db = this.client.db(dbName);
34
+ logger.info('Mongo db initialized');
26
35
  }
27
36
 
28
37
 
29
38
  /**
30
39
  * stops the connection to mongo
31
- * @returns {Promise<void>}
32
40
  */
33
- stop() {
41
+ async stop() {
34
42
  if (!this.db) {
35
- return Promise.resolve();
43
+ return;
36
44
  }
37
- return this.client.close();
45
+ await this.client.close();
38
46
  }
39
47
 
40
48
  collection(collectionName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codefresh-io/service-base",
3
- "version": "6.0.1-beta",
3
+ "version": "6.0.2-beta",
4
4
  "main": "index.js",
5
5
  "description": "",
6
6
  "bin": {
@@ -52,7 +52,7 @@
52
52
  "js-yaml": "^3.13.1",
53
53
  "lodash": "4.17.21",
54
54
  "method-override": "^3.0.0",
55
- "mongodb": "4.17.1",
55
+ "mongodb": "^6.8.0",
56
56
  "morgan": "^1.9.1",
57
57
  "node-uuid": "^1.4.8",
58
58
  "proxyquire": "^1.8.0",