Skip to content

Commit

Permalink
Add check for time period to avoid memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Apr 15, 2021
1 parent 62ce3b0 commit 28060a7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/controllers/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ function scrape(station, startDate, endDate, callback) {
var startDateObj = Moment(startDate).tz('Europe/Zurich');
var endDateObj = Moment(endDate).tz('Europe/Zurich');

// check if the timespan is too long
// since we run into memory errors otherwise
var days = Math.abs(endDateObj.diff(startDateObj, 'days'));
console.log("Requested time period (in days):", days);
var maxDays = 60;
if (days > maxDays) {
callback('Time period too long (' + days + ' days), please request a shorter time period (max: ' + maxDays + ' days)');
return;
}

Request
.post('https://www.tecson-data.ch/zurich/' + station + '/uebersicht/messwerte.php')
.type('form')
Expand Down

0 comments on commit 28060a7

Please sign in to comment.