Skip to content

Commit

Permalink
Merge pull request #88 from gtorodelvalle/bug/do-not-schedule-jobs-af…
Browse files Browse the repository at this point in the history
…ter-new-token

Do not re-schedule update jobs if a new token is requested
  • Loading branch information
gtorodelvalle authored Sep 19, 2016
2 parents 3212c1b + d87321f commit 087c6b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions lib/fiwareDeviceSimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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) {
Expand All @@ -180,6 +186,7 @@ function cancelAllJobs() {
}
}
updateJobs = [];
areJobsScheduled = false;
}

/**
Expand Down Expand Up @@ -848,6 +855,7 @@ function scheduleJobs() {
}
});
}
areJobsScheduled = true;
}

/**
Expand Down Expand Up @@ -930,7 +938,9 @@ function onTokenResponse(err, response, body) {
scheduler.scheduleJob(scheduleDate, requestToken.bind(null, onTokenResponse));
}
emitTokenRequestScheduled(scheduleDate);
scheduleJobs();
if (!areJobsScheduled) {
scheduleJobs();
}
}
}

Expand Down

0 comments on commit 087c6b3

Please sign in to comment.