Skip to content

Commit

Permalink
Storages an empty json in file if it is outdated by more than one hour.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitor-costa committed Dec 6, 2014
1 parent 617724d commit 28f2351
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dataQueuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ function data_formatter() {
return formatted_data;
}

function getDateTimeBoundary(hour) {
var now = new Date();
var offset = hour * 60 * 60 * 1000;

return new Date(now.getTime() - offset);
}

function toDateTime(dateTimeString) {
return new Date(dateTimeString);
}

// Grabs data from riob.us/all and enqueues it in the json file in time intervals
setInterval(function() {
// Make GET Request
Expand All @@ -79,6 +90,9 @@ setInterval(function() {
// Checks if data already has been generated by JSON.parse.
if(data != null) {
// var formatted_data = data_formatter();
if(toDateTime(data.LASTUPDATE) < getDateTimeBoundary(1)) {
data = JSON.parse("{}");
}
appendDataAsync(JSON.stringify(data));
}
}, intervalTime);

0 comments on commit 28f2351

Please sign in to comment.