@@ -22,9 +22,10 @@ let HYDRA_REDIS_DB = 0;
2222const redisPreKey = 'hydra:service' ;
2323const mcMessageKey = 'hydra:service:mc' ;
2424const MAX_ENTRIES_IN_HEALTH_LOG = 1024 ;
25- const PRESENCE_UPDATE_INTERVAL = 1000 ; // unit = milli-seconds, so every second
25+ const ONE_SECOND = 1000 ; // milliseconds
26+ const PRESENCE_UPDATE_INTERVAL = ONE_SECOND ;
2627const HEALTH_UPDATE_INTERVAL = 5000 ;
27- const KEY_EXPIRATION_TTL = parseInt ( PRESENCE_UPDATE_INTERVAL / 1000 ) * 3 ;
28+ const KEY_EXPIRATION_TTL = parseInt ( PRESENCE_UPDATE_INTERVAL / ONE_SECOND ) * 3 ;
2829const UMF_INVALID_MESSAGE = 'UMF message requires "to", "from" and "body" fields' ;
2930
3031/**
@@ -50,15 +51,15 @@ class Hydra extends EventEmitter {
5051 this . serviceDescription = '' ;
5152 this . serviceVersion = '' ;
5253 this . isService = false ;
53- this . initialized = false ;
54- this . ready = ( ) => Promise . reject ( new Error ( 'You must call hydra.init() before invoking hydra.ready()' ) ) ;
5554 this . redisdb = null ;
5655 this . _updatePresence = this . _updatePresence . bind ( this ) ;
5756 this . _updateHealthCheck = this . _updateHealthCheck . bind ( this ) ;
5857 this . registeredRoutes = [ ] ;
5958 this . registeredPlugins = [ ] ;
6059 this . presenceTimerInteval = null ;
6160 this . healthTimerInterval = null ;
61+ this . initialized = false ;
62+ this . ready = ( ) => Promise . reject ( new Error ( 'You must call hydra.init() before invoking hydra.ready()' ) ) ;
6263 }
6364
6465 /**
@@ -260,9 +261,9 @@ class Hydra extends EventEmitter {
260261
261262 /**
262263 * @name _connectToRedis
263- * @summary Configure access to redis and monitor emitted events.
264+ * @summary Configure access to Redis and monitor emitted events.
264265 * @private
265- * @param {object } config - redis client configuration
266+ * @param {object } config - Redis client configuration
266267 * @return {object } promise - resolves or reject
267268 */
268269 _connectToRedis ( config ) {
@@ -275,7 +276,7 @@ class Hydra extends EventEmitter {
275276 this . redisdb = client ;
276277 client
277278 . on ( 'reconnecting' , ( ) => {
278- this . _logMessage ( 'error' , 'Reconnecting to redis server...' ) ;
279+ this . _logMessage ( 'error' , 'Reconnecting to Redis server...' ) ;
279280 } )
280281 . on ( 'warning' , ( warning ) => {
281282 this . _logMessage ( 'error' , `Redis warning: ${ warning } ` ) ;
@@ -292,7 +293,7 @@ class Hydra extends EventEmitter {
292293
293294 /**
294295 * @name _getKeys
295- * @summary Retrieves a list of redis keys based on pattern.
296+ * @summary Retrieves a list of Redis keys based on pattern.
296297 * @param {string } pattern - pattern to filter with
297298 * @return {object } promise - promise resolving to array of keys or or empty array
298299 */
@@ -366,7 +367,7 @@ class Hydra extends EventEmitter {
366367 } ) ;
367368 this . redisdb . set ( `${ redisPreKey } :${ serviceName } :service` , serviceEntry , ( err , _result ) => {
368369 if ( err ) {
369- let msg = 'Unable to set :service key in redis db.' ;
370+ let msg = 'Unable to set :service key in Redis db.' ;
370371 this . _logMessage ( 'error' , msg ) ;
371372 reject ( new Error ( msg ) ) ;
372373 } else {
@@ -473,7 +474,7 @@ class Hydra extends EventEmitter {
473474 /**
474475 * @name _getRoutes
475476 * @summary Retrieves a array list of routes
476- * @param {string } serviceName - name of service to retreieve list of routes.
477+ * @param {string } serviceName - name of service to retrieve list of routes.
477478 * If param is undefined, then the current serviceName is used.
478479 * @return {object } Promise - resolving to array of routes or rejection
479480 */
@@ -599,7 +600,7 @@ class Hydra extends EventEmitter {
599600
600601 /**
601602 * @name _updateHealthCheck
602- * @summary Update service helath .
603+ * @summary Update service heath .
603604 * @private
604605 * @return {undefined }
605606 */
@@ -670,7 +671,7 @@ class Hydra extends EventEmitter {
670671
671672 let entry = Utils . safeJSONStringify ( errMessage ) ;
672673 if ( entry ) {
673- // If issue is with redis we can't use redis to log this error.
674+ // If issue is with Redis we can't use Redis to log this error.
674675 // however the above call to the application logger would be one way of detecting the issue.
675676 if ( this . isService ) {
676677 if ( message . toLowerCase ( ) . indexOf ( 'redis' ) === - 1 ) {
@@ -740,7 +741,7 @@ class Hydra extends EventEmitter {
740741 if ( data ) {
741742 Object . keys ( data ) . forEach ( ( entry ) => {
742743 let item = Utils . safeJSONParse ( data [ entry ] ) ;
743- item . elapsed = parseInt ( ( now - ( new Date ( item . updatedOn ) ) . getTime ( ) ) / 1000 ) ;
744+ item . elapsed = parseInt ( ( now - ( new Date ( item . updatedOn ) ) . getTime ( ) ) / ONE_SECOND ) ;
744745 nodes . push ( item ) ;
745746 } ) ;
746747 }
@@ -964,7 +965,7 @@ class Hydra extends EventEmitter {
964965 * @name _getServiceHealthAll
965966 * @summary Retrieve the health status of all instance services.
966967 * @private
967- * @return {promise } promise - resolves with an array of objects containint instance health information.
968+ * @return {promise } promise - resolves with an array of objects containing instance health information.
968969 */
969970 _getServiceHealthAll ( ) {
970971 return new Promise ( ( resolve , reject ) => {
@@ -1163,7 +1164,7 @@ class Hydra extends EventEmitter {
11631164
11641165 /**
11651166 * @name _sendMessageThroughChannel
1166- * @summary Sends a message to a redis pubsub channel
1167+ * @summary Sends a message to a Redis pubsub channel
11671168 * @param {string } channel - channel name
11681169 * @param {object } message - UMF formatted message object
11691170 * @return {undefined }
@@ -1401,7 +1402,7 @@ class Hydra extends EventEmitter {
14011402 }
14021403 this . redisdb . hget ( `${ redisPreKey } :${ parts [ 0 ] } :configs` , parts [ 1 ] , ( err , result ) => {
14031404 if ( err ) {
1404- let msg = 'Unable to set :configs key in redis db.' ;
1405+ let msg = 'Unable to set :configs key in Redis db.' ;
14051406 this . _logMessage ( 'error' , msg ) ;
14061407 reject ( new Error ( msg ) ) ;
14071408 } else {
@@ -1428,7 +1429,7 @@ class Hydra extends EventEmitter {
14281429 }
14291430 this . redisdb . hset ( `${ redisPreKey } :${ parts [ 0 ] } :configs` , `${ parts [ 1 ] } ` , Utils . safeJSONStringify ( config ) , ( err , _result ) => {
14301431 if ( err ) {
1431- reject ( new Error ( 'Unable to set :configs key in redis db.' ) ) ;
1432+ reject ( new Error ( 'Unable to set :configs key in Redis db.' ) ) ;
14321433 } else {
14331434 resolve ( ) ;
14341435 }
@@ -1446,7 +1447,7 @@ class Hydra extends EventEmitter {
14461447 return new Promise ( ( resolve , reject ) => {
14471448 this . redisdb . hkeys ( `${ redisPreKey } :${ serviceName } :configs` , ( err , result ) => {
14481449 if ( err ) {
1449- let msg = 'Unable to retrieve :config keys from redis db.' ;
1450+ let msg = 'Unable to retrieve :config keys from Redis db.' ;
14501451 this . _logMessage ( 'error' , msg ) ;
14511452 reject ( new Error ( msg ) ) ;
14521453 } else {
@@ -1463,7 +1464,7 @@ class Hydra extends EventEmitter {
14631464
14641465 /**
14651466 * @name _getClonedRedisClient
1466- * @summary get a redis client connection which points to the same Redis server that hydra is using
1467+ * @summary get a Redis client connection which points to the same Redis server that hydra is using
14671468 * @return {object } - Redis Client
14681469 */
14691470 _getClonedRedisClient ( ) {
@@ -1582,7 +1583,7 @@ class Hydra extends EventEmitter {
15821583 return ;
15831584 } else {
15841585 if ( receivedCallBacks === portRanges . length ) {
1585- let msg = 'No available service port in given port range found ' ;
1586+ let msg = 'No available service port in provided port range' ;
15861587 this . _logMessage ( 'error' , msg ) ;
15871588 reject ( msg ) ;
15881589 }
@@ -1656,7 +1657,7 @@ class Hydra extends EventEmitter {
16561657
16571658 /**
16581659 * @name _getParentPackageJSONVersion
1659- * @summary Retreieve the vesion from the host app's package.json file.
1660+ * @summary Retrieve the version from the host app's package.json file.
16601661 * @return {string } version - package version
16611662 */
16621663 _getParentPackageJSONVersion ( ) {
@@ -1678,7 +1679,7 @@ class Hydra extends EventEmitter {
16781679
16791680/**
16801681 * @name IHydra
1681- * @summary Interface to Hydra, can provide microservice funtionality or be used to monitor microservices.
1682+ * @summary Interface to Hydra, can provide microservice functionality or be used to monitor microservices.
16821683 * @fires Hydra#log
16831684 * @fires Hydra#message
16841685 */
@@ -1826,7 +1827,7 @@ class IHydra extends Hydra {
18261827 /**
18271828 * @name getServiceHealthAll
18281829 * @summary Retrieve the health status of all instance services.
1829- * @return {promise } promise - resolves with an array of objects containint instance health information.
1830+ * @return {promise } promise - resolves with an array of objects containing instance health information.
18301831 */
18311832 getServiceHealthAll ( ) {
18321833 return super . _getServiceHealthAll ( ) ;
@@ -2002,7 +2003,7 @@ class IHydra extends Hydra {
20022003
20032004 /**
20042005 * @name getClonedRedisClient
2005- * @summary get a redis client connection which points to the same Redis server that hydra is using
2006+ * @summary get a Redis client connection which points to the same Redis server that hydra is using
20062007 * @return {object } - Redis Client
20072008 */
20082009 getClonedRedisClient ( ) {
0 commit comments