diff --git a/lib/agent/actions/triggers/index.js b/lib/agent/actions/triggers/index.js index 9b628243b..a60ce2e0c 100644 --- a/lib/agent/actions/triggers/index.js +++ b/lib/agent/actions/triggers/index.js @@ -13,7 +13,7 @@ var running_triggers = []; var event_triggers = {}; var current_triggers = []; - +let timeoutStartTrigger; let websocket = require('../../plugins/control-panel/websockets'); const events_list = [ @@ -748,23 +748,23 @@ function handle_triggers_succesfully(success, id, cb, triggers = null) { } function refresh_triggers(id, cb) { - logger.debug('retrieving triggers from API'); + logger.info('retrieving triggers from API'); emitter = emitter || new EventEmitter(); - - fetch_triggers((err, res) => { - if (err) { - handle_triggers_succesfully(false, id, cb); - } else { - var fetched_triggers = res.body; - - if (!(fetched_triggers instanceof Array)) { - return done(id, new Error('Triggers list is not an array'), cb); + if (timeoutStartTrigger) clearTimeout(timeoutStartTrigger); + timeoutStartTrigger = setTimeout(() => { + fetch_triggers((err, res) => { + if (err) { + handle_triggers_succesfully(false, id, cb); + } else { + var fetched_triggers = res.body; + if (!(fetched_triggers instanceof Array)) { + return done(id, new Error('Triggers list is not an array'), cb); + } + handle_triggers_succesfully(true, id, cb, fetched_triggers); } - - handle_triggers_succesfully(true, id, cb, fetched_triggers); - } - }); + }); + }, 8000); } exports.clear_triggers = (cb) => {