Skip to content

Commit

Permalink
Merge pull request #795 from prey/Fix-triggers-action-wait-for-seconds
Browse files Browse the repository at this point in the history
Triggers action wait for 8 seconds before doing the http request
  • Loading branch information
SoraKenji authored Jul 20, 2023
2 parents f9d1146 + 965ae53 commit c54a707
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/agent/actions/triggers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit c54a707

Please sign in to comment.