1.4.1 • Published 6 years ago

queuep v1.4.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Build Status Code Climate Coverage Status

Pronounced: "queue-pea" https://pupudu.gitbooks.io/queuep https://pupudu.gitbooks.io/queuep

An API which will be consumed by multiple clients will eventually reach a point when the resources of the hosting server is insufficient to handle the incoming load.

QueueP to the Rescue !!

QueueP can be used in any context where performance is affected by a heavy load of data.

Demo

A live demo of how QueueP works can be found at https://queuep-fruit-salad.stackblitz.io

The source code of the demo can be found at https://stackblitz.com/edit/queuep-fruit-salad

Feel free to edit the demo code in realtime and fork it on Stack Blitz.

Table of Contents

Why QueueP?

None of the similar queue libraries have a concept of avoiding duplicate requests. QueueP filters out redundant requests and allows to process useful data.

QueueP internally uses concepts such as memoization, throttling and producer-consumer pattern to provide a premium user experience.

QueueP allows you to customize the memoization logic (deciding whether or not to process a data chunk) via the dirty checkers. While you can write the dirty checkers all by yourself, QueueP provides several dirty checker templates which can be quite handy to use.

Basic Usage

Let's assume that multiple devices are sending data about their online status.

First, let's create a queue with the minimal required configurations.

import qp from 'queuep';

qp.initQueue("app_online_status", {
    consumer: function(key, data, done) {
        // Logic to process the online status data goes here
        
        // key - to identify the device corresponding to the online status data
        // data - online status of the corresponding device
        // done - an error-first callback to signal the queue, that the operation has been completed
    }
});

Then we can publish data to the queue.

qp.publish("app_online_status", deviceId, onlineStatus);

Notes about initQueue

  • 1: The first argument is used to identify the queue. An application can have any number of queuep queues.

  • 2: The second argument is an options object. consumer is the only compulsory attribute & should be a function which accepts 3 arguments.

First two arguments will give the key and the data published from the publish method. The optional 3rd argument is an error-first callback that should be used to signal the queue that the consume task has finished.

function consumer(key, data, done) {

    let onlineStatus = data,
        deviceId = key;

    myDbModule.updateOnlineStatus(deviceId, onlineStatus, function (err) {
        if (err) {
            return done(err)
        }
        return done();
    });
}

If the 3rd argument is not provided, then the function should return a promise to signal that the operation has finished. If the actual code which processes the online status returns a promise, then you can return the function call directly.

function consumer(key, data) {
    return myDbModule.updateOnlineStatus(key, data); // calling updateOnlineStatus should return a promise 
    // key: deviceId, data: onlineStatus
}

Installation

To install the stable version:

npm install --save queuep

Documentation

We have started writing a gitbook to give the users a thorough understanding about the framework. The book is still not complete, but do visit https://pupudu.gitbooks.io/queuep/content/ or http://queuep.netlify.com/ and have a look to see where it is heading. We promise to finish it soon.

Background

I wrote queuep to fix an issue in a project I was working on. The story in brief and the fundamental advantages of using QueueP can be found at https://pupudu.gitbooks.io/queuep/content/background.html

License

MIT

1.4.1

6 years ago

1.4.0

6 years ago

1.3.13

6 years ago

1.3.12

6 years ago

1.3.11

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.20

7 years ago

1.2.19

7 years ago

1.2.18

7 years ago

1.2.17

7 years ago

1.2.16

7 years ago

1.2.15

7 years ago

1.2.14

7 years ago

1.2.13

7 years ago

1.2.12

7 years ago

1.2.11

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.30

7 years ago

1.1.29

7 years ago

1.1.28

7 years ago

1.1.27

7 years ago

1.1.26

7 years ago

1.1.25

7 years ago

1.1.24

7 years ago

1.1.23

7 years ago

1.1.22

7 years ago

1.1.21

7 years ago

1.1.20

7 years ago

1.1.19

7 years ago

1.1.18

7 years ago

1.1.17

7 years ago

1.1.16

7 years ago

1.1.15

7 years ago

1.1.14

7 years ago

1.1.13

7 years ago

1.1.12

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago