Skip to content

Instantly share code, notes, and snippets.

@wilcoschoneveld
Last active October 14, 2019 13:49
Show Gist options
  • Save wilcoschoneveld/c4cc6658c0c1c234718fb8091188b3aa to your computer and use it in GitHub Desktop.
Save wilcoschoneveld/c4cc6658c0c1c234718fb8091188b3aa to your computer and use it in GitHub Desktop.
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