Socket
Socket
Sign inDemoInstall

firebase-simple-queue

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    firebase-simple-queue

Simple queue implementation for firebase cloud functions and realtime database


Version published
Weekly downloads
3
decreased by-86.96%
Maintainers
1
Install size
7.00 kB
Created
Weekly downloads
 

Readme

Source

firebase-simple-queue

Downloads Version License

Simple queue implementation for firebase cloud functions and realtime database

The queue will sequentially run each task added in the queue

If your calllback is asyncronous, make sure to await each asyncronous subtasks or async functions, otherwise the queue could not work properly

Installation

yarn add firebase-simple-queue

or using npm

npm install --save firebase-simple-queue

Usage

Initialize the queue in cloud functions index

// Import the plugin
import queue from 'firebase-simple-queue'

/* Define a callback with your custom async logic
 * You callback will receve as parameter witch you have been pushed in the task
 */
function callback(task, context) {
  return new Promise(resolve => {
    setTimeout(() => {
      // Do whatever you want.
      resolve()
    }, 5000)
  })
}

/* Initialize the queue
 * @param key A key for the realtime database tree
 * @param callback The callback with your custom logic
 */
const { onCreateTask, onFinishTask, onRetryTask } = queue('somePath/{someParam}/queue', callback)

// Now register the cloud functions triggers
export {
  // ...another functions
  onCreateTask,
  onFinishTask,
  onRetryTask
}

Add an index in database.rules

{
  "rules": {
    "queue": {
      "tasks": {
        ".indexOn": "_error"
      }
    }
  }
}

Example

Now in your client just add a task in the queue

const myTaskObject = { attr1: 'Test1', another_attr: 123 }

// Your task can be a number, string or object
database
  .ref('queue')
  .child('tasks')
  .push(myTaskObject)

What about errors

If a task throws an error, the details will be in a _error key inside the task. To try run a task with error again, just remove the key _error

The task with the key _error will be ignored in the execution queue. Ex: If I have 3 tasks in the queue and the first one is in error, the queue will only execute tasks 2 and 3.

Development

Just edit the code, commit, and run ./publish.sh

Contribution

You can open an issue or send a pull request

Author

Daniel Fernando Lourusso - dflourusso@gmail.com

Keywords

FAQs

Last updated on 23 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc