Last active
October 14, 2019 13:49
-
-
Save wilcoschoneveld/c4cc6658c0c1c234718fb8091188b3aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface GoogleCalendarEvent { | |
id: string; | |
summary: string; | |
description: string; | |
} | |
async pollCalendarEvents() { | |
// Define a range of twice the polling interval (in case of polling delays) | |
const timeNow = new Date(); | |
const timeMin = new Date(timeNow.getTime() - this.POLLING_INTERVAL * 2); | |
try { | |
// Request all events in the selected calendar in the selected range | |
const response = await this.calendar.events.list({ | |
calendarId: process.env.EVENT_CALENDAR_ID, | |
singleEvents: true, // Flatten any recurring events | |
timeMin: timeMin.toISOString(), | |
timeMax: timeNow.toISOString() | |
}); | |
const events = response.data.items as GoogleCalendarEvent[]; | |
// Process events one by one (sequentially) | |
for (const event of events) { | |
await this.processEvent(event); | |
} | |
} catch (err) { | |
// log error | |
} | |
// Keep the interval job running | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment