npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

@star__hoshi/only-once

0.1.3 • Public • Published

only-once

Prevent duplicate execution of Cloud Functions.
You should read this blog. firestore cloud functions onCreate/onDelete sometimes immediately triggered twice

Installation

npm install @star__hoshi/only-once --save
yarn add @star__hoshi/only-once

Usage

import * as OnlyOnce from '@star__hoshi/only-once'
 
OnlyOnce.initialize(admin.firestore())
 
export const updateUser = functions.firestore.document('user/{userId}').onCreate(async (change, context) => {
  const wasTriggered = await OnlyOnce.wasTriggered(context.eventId)
  if (wasTriggered) {
    console.log(`EventID: ${context.eventId} was already triggered!`)
    return undefined
  }
 
  // exec only once
 
  return undefined
})

install

npm i @star__hoshi/only-once

Downloadsweekly downloads

35

version

0.1.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability