@star__hoshi/only-once
TypeScript icon, indicating that this package has built-in type declarations

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
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.3
    0

Package Sidebar

Install

npm i @star__hoshi/only-once

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

161 kB

Total Files

11

Last publish

Collaborators

  • star__hoshi