File tree Expand file tree Collapse file tree 4 files changed +71
-949
lines changed Expand file tree Collapse file tree 4 files changed +71
-949
lines changed Original file line number Diff line number Diff line change @@ -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' ) ;
Original file line number Diff line number Diff line change @@ -9,32 +9,39 @@ 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 ;
21
19
const dbName = config . mongo . dbName || getDbNameFromUri ( uri ) ;
22
- const client = await MongoClient . connect ( uri , clientSettings ) ;
20
+ const client = new MongoClient ( uri , clientSettings ) ;
21
+ logger . info ( `Mongo db name ${ dbName } ` ) ;
22
+
23
+ try {
24
+ await client . connect ( ) ;
25
+ logger . info ( 'Mongo driver connected' ) ;
26
+ } catch ( error ) {
27
+ logger . error ( 'Error connecting to MongoDB:' , error ) ;
28
+ throw error ;
29
+ }
30
+
23
31
this . client = client ;
24
- this . db = client . db ( dbName ) ;
25
- logger . info ( 'Mongo driver connected ' ) ;
32
+ this . db = this . client . db ( dbName ) ;
33
+ logger . info ( 'Mongo db initialized ' ) ;
26
34
}
27
35
28
36
29
37
/**
30
38
* stops the connection to mongo
31
- * @returns {Promise<void> }
32
39
*/
33
- stop ( ) {
40
+ async stop ( ) {
34
41
if ( ! this . db ) {
35
- return Promise . resolve ( ) ;
42
+ return ;
36
43
}
37
- return this . client . close ( ) ;
44
+ await this . client . close ( ) ;
38
45
}
39
46
40
47
collection ( collectionName ) {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @codefresh-io/service-base" ,
3
- "version" : " 6 .0.0" ,
3
+ "version" : " 7 .0.0" ,
4
4
"main" : " index.js" ,
5
5
"description" : " " ,
6
6
"bin" : {
52
52
"js-yaml" : " ^3.13.1" ,
53
53
"lodash" : " 4.17.21" ,
54
54
"method-override" : " ^3.0.0" ,
55
- "mongodb" : " ^4.17.2 " ,
55
+ "mongodb" : " 6.3.0 " ,
56
56
"morgan" : " ^1.9.1" ,
57
57
"node-uuid" : " ^1.4.8" ,
58
58
"proxyquire" : " ^1.8.0" ,
You can’t perform that action at this time.
0 commit comments