Skip to content

Instantly share code, notes, and snippets.

@nkmrh
Last active June 12, 2018 00:42
Show Gist options
  • Save nkmrh/0c7f374e68513ed5784718b7b756e79e to your computer and use it in GitHub Desktop.
Save nkmrh/0c7f374e68513ed5784718b7b756e79e to your computer and use it in GitHub Desktop.
export async function wasTriggered(eventId: string) {
return firestore.runTransaction(async t => {
const ref = eventIdRef
const doc = await t.get(ref)
if (doc.exists) {
return true
} else {
t.set(ref, {})
return false
}
})
}
export const listener = functions.firestore.document(`path`).onCreate(async (snapshot, context) => {
if (await utils.wasTriggered(context.eventId)) {
console.log('Ignore: it has already been triggered')
return 0
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment