aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/getMeetingpointData.js11
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/getMeetingpointData.js b/lib/getMeetingpointData.js
index 9a51cfb..94cf36c 100644
--- a/lib/getMeetingpointData.js
+++ b/lib/getMeetingpointData.js
@@ -59,7 +59,7 @@ function getValidWeekNumbers(page) {
function requestData() {
lastUpdate = new Date()
- return request(`http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm`).then((response) => {
+ return request(`http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm`, { timeout: 5000 }).then((response) => {
const page = cheerio.load(response.body)
const users = getUsers(page)
const validWeekNumbers = getValidWeekNumbers(page)
@@ -71,17 +71,10 @@ function requestData() {
}
function getMeetingpointData () {
- if (lastUpdate == null) {
+ if (lastUpdate == null || new Date() - lastUpdate > 10 * 60 * 1000) { // 10 minutes
return requestData()
} else if (!meetingpointData) {
- // The first request hasn't resolved yet, throw an error.
return Promise.reject()
- } else if (new Date() - lastUpdate > 10 * 60 * 1000) { // 10 minutes
- return requestData().catch(function () {
- console.warn('Unable to update userIndex, using cached.')
-
- return meetingpointData
- })
} else {
return Promise.resolve(meetingpointData)
}