-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from getwud/feature/#500_add_trigger_testing_…
…feature ⭐ [UI/API] - Add support for manually running triggers to help w…
- Loading branch information
Showing
17 changed files
with
297 additions
and
93 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
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 |
---|---|---|
@@ -1,30 +1,15 @@ | ||
const registry = require('../registry'); | ||
const component = require('./component'); | ||
|
||
/** | ||
* Return registered registries. | ||
* @returns {{id: string}[]} | ||
*/ | ||
function getRegistries() { | ||
return registry.getState().registry; | ||
} | ||
/** | ||
* Init Router. | ||
* @returns {*} | ||
*/ | ||
function init() { | ||
return component.init(getRegistries); | ||
} | ||
|
||
/** | ||
* Get all triggers. | ||
* @returns {{id: string}[]} | ||
*/ | ||
function getAllRegistries() { | ||
return component.mapComponentsToList(getRegistries); | ||
const router = component.init('registry'); | ||
router.get('/:name', (req, res) => component.getById(req, res, 'registry')); | ||
return router; | ||
} | ||
|
||
module.exports = { | ||
init, | ||
getAllRegistries, | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,51 @@ | ||
const registry = require('../registry'); | ||
const component = require('./component'); | ||
const registry = require('../registry'); | ||
|
||
/** | ||
* Return registered triggers. | ||
* @returns {{id: string}[]} | ||
* Run a specific trigger on a specific container provided in the payload. | ||
* @param {*} req | ||
* @param {*} res | ||
* @returns | ||
*/ | ||
function getTriggers() { | ||
return registry.getState().trigger; | ||
async function runTrigger(req, res) { | ||
const triggerType = req.params.type; | ||
const triggerName = req.params.name; | ||
const containerToTrigger = req.body; | ||
|
||
const triggerToRun = registry.getState().trigger[`trigger.${triggerType}.${triggerName}`]; | ||
if (!triggerToRun) { | ||
res.status(404).json({ | ||
error: `Error when running trigger ${triggerType}.${triggerName} (trigger not found)`, | ||
}); | ||
return; | ||
} | ||
if (!containerToTrigger) { | ||
res.status(400).json({ | ||
error: `Error when running trigger ${triggerType}.${triggerName} (container is undefined)`, | ||
}); | ||
return; | ||
} | ||
|
||
try { | ||
await triggerToRun.trigger(containerToTrigger); | ||
res.status(200).json({}); | ||
} catch (e) { | ||
res.status(500).json({ | ||
error: `Error when running trigger ${triggerType}.${triggerName} (${e.message})`, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Init Router. | ||
* @returns {*} | ||
*/ | ||
function init() { | ||
return component.init(getTriggers); | ||
} | ||
|
||
/** | ||
* Get all triggers. | ||
* @returns {{id: string}[]} | ||
*/ | ||
function getAllTriggers() { | ||
return component.mapComponentsToList(getTriggers); | ||
const router = component.init('trigger'); | ||
router.post('/:type/:name', (req, res) => runTrigger(req, res)); | ||
return router; | ||
} | ||
|
||
module.exports = { | ||
init, | ||
getAllTriggers, | ||
}; |
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 |
---|---|---|
@@ -1,31 +1,13 @@ | ||
const registry = require('../registry'); | ||
const component = require('./component'); | ||
|
||
/** | ||
* Return registered watchers. | ||
* @returns {{id: string}[]} | ||
*/ | ||
function getWatchers() { | ||
return registry.getState().watcher; | ||
} | ||
|
||
/** | ||
* Init Router. | ||
* @returns {*} | ||
*/ | ||
function init() { | ||
return component.init(getWatchers); | ||
} | ||
|
||
/** | ||
* Get all watchers. | ||
* @returns {{id: string}[]} | ||
*/ | ||
function getAllWatchers() { | ||
return component.mapComponentsToList(getWatchers); | ||
return component.init('watcher'); | ||
} | ||
|
||
module.exports = { | ||
init, | ||
getAllWatchers, | ||
}; |
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
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
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
Oops, something went wrong.