Skip to content

Instantly share code, notes, and snippets.

@nkmrh
Created February 23, 2018 05:49
Show Gist options
  • Save nkmrh/cce1c8565932d43e193923596b814b4d to your computer and use it in GitHub Desktop.
Save nkmrh/cce1c8565932d43e193923596b814b4d to your computer and use it in GitHub Desktop.
It prevents the same event ID from being executed more than once
var alreadyRunEventIDs = [];
function isAlreadyRunning(eventID) {
return alreadyRunEventIDs.indexOf(eventID) >= 0;
}
function markAsRunning(eventID) {
alreadyRunEventIDs.push(eventID);
}
exports.notifyNewPost = functions.firestore.document('path').onCreate(event => {
const eventID = event.eventId;
if (util.isAlreadyRunning(eventID)) {
return console.log('Ignore it because it is already running (eventId):', eventID);
}
markAsRunning(eventID);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment