From d87321f41dfa5361388fe47bef5218e9acd8fec7 Mon Sep 17 00:00:00 2001 From: German Toro del Valle Date: Mon, 19 Sep 2016 13:03:03 +0200 Subject: [PATCH] Do not re-schedule update jobs if a new token is requested --- README.md | 1 + lib/fiwareDeviceSimulator.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aaf3bcd..6e2e8a6 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ An example simulation configuration file is shown next to give you a glimpse of } }, "json": { + "api_key": "83ut64ib3gzs6km6izubjyenu", "http": { "protocol": "http", "host": "localhost", diff --git a/lib/fiwareDeviceSimulator.js b/lib/fiwareDeviceSimulator.js index 50110b3..8e64150 100644 --- a/lib/fiwareDeviceSimulator.js +++ b/lib/fiwareDeviceSimulator.js @@ -61,6 +61,12 @@ var isMQTTClientConnected = false; */ var eventEmitter = new EventEmitter(); +/** + * Flag indicating if the jobs have been already scheduled + * @type {Boolean} + */ +var areJobsScheduled = false; + /** * Array of update scheduled jobs * @type {Array} @@ -171,7 +177,7 @@ function cloneEntity(entity) { } /** - * Cancels all the pending (token request and update) jobs + * Cancels all the pending (token request and update) jobs if any */ function cancelAllJobs() { for (var job in scheduler.scheduledJobs) { @@ -180,6 +186,7 @@ function cancelAllJobs() { } } updateJobs = []; + areJobsScheduled = false; } /** @@ -848,6 +855,7 @@ function scheduleJobs() { } }); } + areJobsScheduled = true; } /** @@ -930,7 +938,9 @@ function onTokenResponse(err, response, body) { scheduler.scheduleJob(scheduleDate, requestToken.bind(null, onTokenResponse)); } emitTokenRequestScheduled(scheduleDate); - scheduleJobs(); + if (!areJobsScheduled) { + scheduleJobs(); + } } }