-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented plugins * added HydraEvent and HydraPlugin modules * handle errors during plugin initialization * added plugins.md with plugin tutorial * added table of contents to documentation.md
- Loading branch information
Showing
6 changed files
with
341 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @name HydraEvent | ||
* @description EventEmitter event names for Hydra | ||
*/ | ||
class HydraEvent { | ||
/** | ||
* @return {string} config update event | ||
* @static | ||
*/ | ||
static get CONFIG_UPDATE_EVENT() { | ||
return 'configUpdate'; | ||
} | ||
/** | ||
* @return {string} update message type | ||
* @static | ||
*/ | ||
static get UPDATE_MESSAGE_TYPE() { | ||
return 'configRefresh'; | ||
} | ||
} | ||
|
||
module.exports = HydraEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
const isEqual = require('lodash/isEqual'); | ||
const HydraEvent = require('./events'); | ||
|
||
/** | ||
* @name HydraPlugin | ||
* @description Extend this for hydra plugins | ||
*/ | ||
class HydraPlugin { | ||
/** | ||
* @param {string} pluginName - unique name for the plugin | ||
*/ | ||
constructor(pluginName) { | ||
this.name = pluginName; | ||
} | ||
/** | ||
* @name setHydra | ||
* @param {object} hydra - hydra instance | ||
*/ | ||
setHydra(hydra) { | ||
this.hydra = hydra; | ||
this.hydra.on( | ||
HydraEvent.CONFIG_UPDATE_EVENT, | ||
config => this.updateConfig(config) | ||
); | ||
} | ||
/** | ||
* @name setConfig | ||
* @param {object} hydraConfig - the hydra config | ||
*/ | ||
setConfig(hydraConfig) { | ||
this.hydraConfig = hydraConfig; | ||
this.opts = hydraConfig.plugins[this.name]; | ||
} | ||
/** | ||
* @name updateConfig | ||
* @param {object} serviceConfig - the service-level config | ||
* @param {object} serviceConfig.hydra - the hydra-level config | ||
*/ | ||
updateConfig(serviceConfig) { | ||
this.serviceConfig = serviceConfig; | ||
this.hydraConfig = serviceConfig.hydra; | ||
let opts = this.hydraConfig.plugins[this.name]; | ||
if (!isEqual(this.opts, opts)) { | ||
this.configChanged(opts); | ||
} | ||
} | ||
/** | ||
* @name configChanged | ||
* @summary Handles changes to the plugin configuration | ||
* @param {object} opts - the new plugin config | ||
*/ | ||
configChanged(opts) { | ||
console.log(`[override] [${this.name}] handle changed config`); | ||
console.dir(opts, {colors: true, depth: null}); | ||
} | ||
/** | ||
* @name onServiceReady | ||
* @summary Called by Hydra when the service has initialized, but before the init Promise resolves | ||
*/ | ||
onServiceReady() { | ||
console.log(`[override] [${this.name}] hydra service ready`); | ||
} | ||
} | ||
|
||
module.exports = HydraPlugin; |
Oops, something went wrong.