Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

russellsantos/mock-kue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mock-kue is a small mocking library for kue. It mocks out trigger and process functions in kue, while maintaining the jobs in an internal array. You can then inspect the job count and run them at any given time. No connection to redis will be made by kue.

Installation

Node.js:

npm install mock-kue

To use, simply require the library:

require('mock-kue');

Job Count

You can inspect the job count as follows:

var kue = require('kue'),
    jobs = kue.createQueue();

jobs.create('email', {
    title: 'welcome email for tj'
  , to: 'tj@learnboost.com'
  , template: 'welcome-email'
}).save();

kue.jobCount(); // -> '1'

Processing Jobs

To process the jobs in the queue, you need to call the .drain() method. .drain() returns a promise. The promise will be fulfilled once all the jobs are done processing. Here's an example:

kue.drain()
.then(function() {
    kue.jobCount(); // -> '0'
}, function(err) {
    // there was an error in processing the jobs
    console.log(err.message); 
});

Clearing Jobs

To clear a job, call the .clear() method:

jobs.create(...).save();
kue.jobCount(); // -> '1'
kue.clear();
kue.jobCount(); // -> '0'

Inspecting Jobs

To get the access to created jobs, call the .getJobs() method:

jobs.create(...).save();
jobs.create(...).save();
kue.jobCount(); // -> '2'
kue.getJobs(); // -> returns the array of created jobs

License

Copyright (c) 2014 built.io team. This software is licensed under the MIT License.

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%