0.9.26 • Published 4 years ago

mongoose-kue v0.9.26

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

mongoose-kue

Build Status Dependency Status npm version

mongoose plugin to run mongoose schema methods in background.

Note!: It's highly advice to run worker(s) in separate process for better performance

Requirements

  • NodeJS v10.0+

Install

$ npm install --save mongoose kue mongoose-kue

Usage

const mongoose = require('mongoose');
const { Schema } = mongoose;
const { plugin: runInBackground, worker } = require('mongoose-kue');

...

/* queue sendEmail instance method to run in background */
const job =
  user.runInBackground({ method: 'sendSMS', to: ['255714000111'] });

/* queue sendEmail static method in background */
const job =
  User.runInBackground({
    method: 'sendEmail',
    to: ['a@example.com', 'b@example.com']
  });


/* ADVICED: in separate process start processing */
worker.start();

...

Options

Plugin

const { plugin: runInBackground } = require('mongoose-kue');

mongoose.plugin(runInBackground, {
  name: 'mongoose',
  prefix: 'q',
  MONGODB_URI: process.env.MONGODB_URI,
  redis: (process.env.REDIS_URL || {
    port: 1234,
    host: '10.0.50.20',
    auth: 'password',
    db: 3
  })
});

...

Worker

Note!: I highly recommend to run this in separate process

const mongoose = require('mongoose');
const { worker } = require('mongoose-kue');

/* load and register your models */

...

/* start worker queue to process in background */
worker.start({
  name: 'mongoose',
  concurrency: 10,
  prefix: 'q',
  MONGODB_URI: process.env.MONGODB_URI,
  redis: (process.env.REDIS_URL || {
    port: 1234,
    host: '10.0.50.20',
    auth: 'password',
    db: 3
  })
});

Environment

KUE_NAME=mongoose
KUE_JOB_TYPES=mongoose
KUE_TIMEOUT=5000
KUE_CONCURRENCY=10
KUE_MAX_ATTEMPTS=3
KUE_PRIORITY=normal
KUE_JOB_EVENTS=false
KUE_REMOVE_ON_COMPLETE=true
KUE_REDIS_URL=redis://127.0.0.1:3000
KUE_HTTP_PORT=5000
KUE_HTTP_USERNAME=kue
KUE_HTTP_PASSWORD=kue
REDIS_URL=redis://127.0.0.1:3000

References

Testing

  • Clone this repository

  • Install all development dependencies

$ npm install
  • Then run test
$ npm test

Contribute

It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.

Licence

The MIT License (MIT)

Copyright (c) lykmapipo & Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.9.26

4 years ago

0.9.25

4 years ago

0.9.24

4 years ago

0.9.23

4 years ago

0.9.22

4 years ago

0.9.21

4 years ago

0.9.20

4 years ago

0.9.19

4 years ago

0.9.18

4 years ago

0.9.17

4 years ago

0.9.16

4 years ago

0.9.15

4 years ago

0.9.14

4 years ago

0.9.13

4 years ago

0.9.12

4 years ago

0.9.11

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.9

5 years ago

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago