Giter Club home page Giter Club logo

firelease's Introduction

Firelease

A Firebase queue consumer for Node with at-least-once and at-most-once semantics, fine-grained concurrency controls, and support for promises and generators. Built on top of Nodefire.

API

The module exposes one function:

function attachWorker(ref, options, worker)

Attaches a worker function to consume tasks from a queue. You should normally attach no more than one worker per path in any given process, but it's OK to run multiple processes on the same paths concurrently.

  • @param {Nodefire} ref A Nodefire ref to the queue root in Firebase. Individual tasks will be children of this root and must be objects. The _lease key is reserved for use by Firelease in each task.

  • @param {Object} options Optional options, supporting the following values:

    • maxConcurrent: {number} max number of tasks to handle concurrently for this worker.
    • bufferSize: {number} upper bound on how many tasks to keep buffered and potentially go through leasing transactions in parallel; not worth setting higher than maxConcurrent, or higher than about 10.
    • minLease: {number | string} minimum duration of each lease, which should equal the maximum expected time a worker will take to handle a task; specified as either a number of milliseconds, or a human-readable duration string.
    • maxLease: {number | string} maximum duration of each lease, same format as minLease; the lease duration is doubled each time a task fails until it reaches maxLease.
  • @param {function(Object):RETRY | number | string | undefined} worker The worker function that handles enqueued tasks. It will be given a task object as argument, with a special $ref attribute set to the Nodefire ref of that task. The worker can perform arbitrary computation whose duration should not exceed the queue's minLease value. It can manipulate the task itself in Firebase as well, e.g. to delete it (to get at-most-once queue semantics) or otherwise modify it. The worker can return RETRY to cause the task to be retried after the current lease expires (and reset the lease backoff counter), or a duration after which the task should be retried relative to when it was started (as either a number of milliseconds or a human-readable duration string). If the worker returns nothing then the task is considered completed and removed from the queue. All of these values can also be wrapped in a promise or a generator, which will be dealt with appropriately.

There are also some module-level settings you can change:

globalMaxConcurrent: {number}

Set this to the maximum number of concurrent tasks being executed at any moment across all queues.

defaults: {Object}

Default option values for all subsequent attachWorker calls. See that function for details.

captureError: {function(Error)}

A function used to capture errors. Defaults to logging the stack to the console, but you may want to change it to something else in production. The function should take a single exception argument.

firelease's People

Contributors

pkaminski avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.