diff --git a/app/api/trigger.js b/app/api/trigger.js index 0e2e447c..ae49dd71 100644 --- a/app/api/trigger.js +++ b/app/api/trigger.js @@ -1,5 +1,6 @@ const component = require('./component'); const registry = require('../registry'); +const log = require('../log').child({ component: 'trigger' }); /** * Run a specific trigger on a specific container provided in the payload. @@ -14,12 +15,14 @@ async function runTrigger(req, res) { const triggerToRun = registry.getState().trigger[`trigger.${triggerType}.${triggerName}`]; if (!triggerToRun) { + log.warn(`No trigger found(type=${triggerType}, name=${triggerName})`); res.status(404).json({ error: `Error when running trigger ${triggerType}.${triggerName} (trigger not found)`, }); return; } if (!containerToTrigger) { + log.warn(`Trigger cannot be executed without container (type=${triggerType}, name=${triggerName})`); res.status(400).json({ error: `Error when running trigger ${triggerType}.${triggerName} (container is undefined)`, }); @@ -28,8 +31,10 @@ async function runTrigger(req, res) { try { await triggerToRun.trigger(containerToTrigger); + log.info(`Trigger executed with success (type=${triggerType}, name=${triggerName}, container=${JSON.stringify(containerToTrigger)})`); res.status(200).json({}); } catch (e) { + log.warn(`Trigger cannot be executed without container (type=${triggerType}, name=${triggerName})`); res.status(500).json({ error: `Error when running trigger ${triggerType}.${triggerName} (${e.message})`, }); diff --git a/ui/src/components/ContainerFilter.vue b/ui/src/components/ContainerFilter.vue index 611532ba..9f4ec456 100644 --- a/ui/src/components/ContainerFilter.vue +++ b/ui/src/components/ContainerFilter.vue @@ -127,7 +127,7 @@ export default { this.isRefreshing = true; try { const body = await refreshAllContainers(); - this.$root.$emit("notify", `All containers refreshed`); + this.$root.$emit("notify", "All containers refreshed"); this.$emit("refresh-all-containers", body); } catch (e) { this.$root.$emit( diff --git a/ui/src/components/SnackBar.vue b/ui/src/components/SnackBar.vue index 5e993f64..09d1e2a1 100644 --- a/ui/src/components/SnackBar.vue +++ b/ui/src/components/SnackBar.vue @@ -22,7 +22,7 @@ export default { }, timeout: { type: Number, - default: 2000, + default: 4000, }, message: { type: String, diff --git a/ui/src/components/TriggerDetail.vue b/ui/src/components/TriggerDetail.vue index ff33b5dc..5490b310 100644 --- a/ui/src/components/TriggerDetail.vue +++ b/ui/src/components/TriggerDetail.vue @@ -10,85 +10,8 @@ - - - - mdi-test-tube - Test trigger - - - - - - - - Run trigger - - - + - - - Test - mdi-test-tube - - Default configuration + + + Test + mdi-test-tube + + + + + + mdi-test-tube + Test trigger + + + + + + + + Run trigger + + + @@ -132,7 +141,8 @@ export default { data() { return { showDetail: true, - testForm: false, + showTestForm: false, + isTriggering: false, container: { id: "123456789", name: "container_test", @@ -179,11 +189,23 @@ export default { this.showDetail = !this.showDetail; }, async runTrigger() { - await runTrigger({ - triggerType: this.trigger.type, - triggerName: this.trigger.name, - container: this.container, - }); + this.isTriggering = true; + try { + await runTrigger({ + triggerType: this.trigger.type, + triggerName: this.trigger.name, + container: this.container, + }); + this.$root.$emit("notify", "Trigger executed with success"); + } catch (err) { + this.$root.$emit( + "notify", + `Trigger executed with error (${err.message}})`, + "error", + ); + } finally { + this.isTriggering = false; + } }, }, filters: { diff --git a/ui/src/services/trigger.js b/ui/src/services/trigger.js index 70b02bd3..94f275fb 100644 --- a/ui/src/services/trigger.js +++ b/ui/src/services/trigger.js @@ -13,7 +13,11 @@ async function runTrigger({ triggerType, triggerName, container }) { headers: { "Content-Type": "application/json" }, body: JSON.stringify(container), }); - return response.json(); + const json = await response.json(); + if (response.status !== 200) { + throw new Error(json.error ? json.error : "Unknown error"); + } + return json; } export { getTriggerIcon, getAllTriggers, runTrigger };