Created
February 23, 2018 05:49
-
-
Save nkmrh/cce1c8565932d43e193923596b814b4d to your computer and use it in GitHub Desktop.
It prevents the same event ID from being executed more than once
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
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