Comparing version 2.2.2 to 2.2.3
@@ -0,1 +1,9 @@ | ||
v.2.2.3 | ||
======= | ||
- Added getJobCounts. | ||
- Fixed global events #394. | ||
[Changes](https://github.com/OptimalBits/bull/compare/v2.2.2...v2.2.3) | ||
v.2.2.2 | ||
@@ -2,0 +10,0 @@ ======= |
@@ -199,2 +199,3 @@ /*eslint-env node */ | ||
listenDistEvent('stalled'); // | ||
listenDistEvent('active'); // | ||
listenDistEvent('completed'); // | ||
@@ -216,5 +217,5 @@ listenDistEvent('failed'); // | ||
args.unshift(eventName); | ||
args.unshift('global:' + eventName); | ||
_this.emit.apply(_this, args); | ||
}); | ||
}, true); | ||
} | ||
@@ -286,2 +287,7 @@ | ||
var args = Array.prototype.slice.call(arguments); | ||
// Emit local event | ||
this.emit.apply(this, args); | ||
// Emit global event | ||
args[0] = args[0] + '@' + this.name; | ||
@@ -600,3 +606,3 @@ return Disturbed.prototype.distEmit.apply(this, args); | ||
return _this.getJobFromId(jobId).then(function(job){ | ||
_this.distEmit('failed', job.toJSON(), new Error('job stalled more than allowable limit')); | ||
_this.distEmit('failed', job, new Error('job stalled more than allowable limit')); | ||
return null; | ||
@@ -607,3 +613,3 @@ }); | ||
return _this.getJobFromId(jobId).then(function(job){ | ||
_this.distEmit('stalled', job.toJSON()); | ||
_this.distEmit('stalled', job); | ||
return null; | ||
@@ -704,3 +710,3 @@ }); | ||
.then(function(){ | ||
return _this.distEmit('completed', job.toJSON(), data); | ||
return _this.distEmit('completed', job, data); | ||
}); | ||
@@ -717,3 +723,3 @@ } | ||
.then(function(){ | ||
return _this.distEmit('failed', job.toJSON(), error); | ||
return _this.distEmit('failed', job, error); | ||
}); | ||
@@ -737,3 +743,3 @@ }, function(err){ | ||
_this.emit('active', job, jobPromise); | ||
_this.distEmit('active', job, jobPromise); | ||
@@ -866,2 +872,23 @@ return jobPromise | ||
/** | ||
* Returns all the job counts for every list/set in the queue. | ||
* | ||
*/ | ||
Queue.prototype.getJobCounts = function(){ | ||
var types = ['wait', 'active', 'completed', 'failed', 'delayed']; | ||
var counts = {}; | ||
return this.client.multi() | ||
.llen(this.toKey('wait')) | ||
.llen(this.toKey('active')) | ||
.scard(this.toKey('completed')) | ||
.scard(this.toKey('failed')) | ||
.zcard(this.toKey('delayed')) | ||
.exec().then(function(result){ | ||
result.forEach(function(res, index){ | ||
counts[types[index]] = res[1] || 0; | ||
}); | ||
return counts; | ||
}); | ||
}; | ||
Queue.prototype.getCompletedCount = function() { | ||
@@ -868,0 +895,0 @@ return this.client.scard(this.toKey('completed')); |
{ | ||
"name": "bull", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Job manager", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
291
README.md
@@ -208,5 +208,9 @@ Bull Job Manager | ||
Events are by default local, i.e., they only fire on the listeners that are registered on the given worker, | ||
if you need to listen to events globally, just set to true the last argument: | ||
if you need to listen to events globally, just prefix the event with ```global:```: | ||
``` | ||
queue.on('completed', listener, true): | ||
// Local Event listener | ||
queue.on('completed', listener): | ||
// Global Event listener | ||
queue.on('global:completed', listener); | ||
``` | ||
@@ -333,2 +337,3 @@ | ||
* [Queue##getJob](#getJob) | ||
* [Queue##getJobCounts](#getJobCounts) | ||
* [Job](#job) | ||
@@ -341,4 +346,9 @@ * [Job##remove](#remove) | ||
<a name="queue"/> | ||
###Queue(queueName, redisPort, redisHost, [redisOpts]) | ||
###Queue(queueName, redisConnectionString, [redisOpts]) | ||
###Queue | ||
```ts | ||
Queue(queueName: string, redisPort: number, redisHost: string, redisOpts?: RedisOpts): Queue | ||
``` | ||
```ts | ||
Queue(queueName: string, redisConnectionString: string, redisOpts? RedisOpts): Queue | ||
``` | ||
@@ -372,3 +382,6 @@ This is the Queue constructor. It creates a new Queue that is persisted in | ||
<a name="process"/> | ||
#### Queue##process([concurrency,] function(job[, done])) | ||
####Queue##Process | ||
```ts | ||
process(concurrency?: number, processor: (job, done?) => Promise<any>) | ||
``` | ||
@@ -427,3 +440,6 @@ Defines a processing function for the jobs placed into a given Queue. | ||
<a name="add"/> | ||
#### Queue##add(data, opts) | ||
#### Queue##add | ||
```ts | ||
add(data: any, opts?: JobOpt): Promise<Job> | ||
``` | ||
@@ -434,41 +450,35 @@ Creates a new job and adds it to the queue. If the queue is empty the job | ||
__Arguments__ | ||
```typescript | ||
interface JobOpts{ | ||
priority: number; // Optional priority value. ranges from 1 (highest priority) to MAX_INT (lowest priority). Note that | ||
// using priorities has a slight impact on performance, so do not use it if not required. | ||
```javascript | ||
data {PlainObject} A plain object with arguments that will be passed to | ||
the job processing function in job.data. | ||
opts A plain object with arguments that will be passed to the job | ||
processing function in job.opts. | ||
{ | ||
priority {Number} Optional priority value, ranges from 1 (highest priority) to MAX_INT (lowest priority). Note that | ||
using priorities has a slight impact on performance, so do not use if not required. | ||
delay: number; // An amount of miliseconds to wait until this job can be processed. Note that for accurate delays, both | ||
// server and clients should have their clocks synchronized. [optional]. | ||
delay {Number} An amount of miliseconds to wait until this job can be processed. Note that for accurate delays, both server and clients should have their clocks synchronized. [optional] | ||
attempts: number; // The total number of attempts to try the job until it completes. | ||
attempts {Number} The total number of attempts to try the job until it completes. | ||
backoff: number | BackoffOpts; // Backoff setting for automatic retries if the job fails | ||
backoff {Number|Object} Backoff setting for automatic retries if the job fails | ||
backoff.type {String} Backoff type, which can be either `fixed` or `exponential` | ||
backoff.delay {Number} Backoff delay, in milliseconds. | ||
lifo: boolean; // if true, adds the job to the right of the queue instead of the left (default false) | ||
timeout: number; // The number of milliseconds after which the job should be fail with a timeout error [optional] | ||
lifo {Boolean} A boolean which, if true, adds the job to the right of the queue | ||
instead of the left (default false) | ||
timeout {Number} The number of milliseconds after which the job should be fail | ||
with a timeout error [optional] | ||
jobId {Number|String} Override the job ID - by default, the job ID is a unique | ||
integer, but you can use this setting to override it. | ||
If you use this option, it is up to you to ensure the | ||
jobId is unique. If you attempt to add a job with an id that | ||
already exists, it will not be added. | ||
removeOnComplete {Boolean} A boolean which, if true, removes the job when it successfully | ||
completes. Default behavior is to keep the job in the completed queue. | ||
} | ||
returns {Promise} A promise that resolves when the job has been succesfully | ||
added to the queue (or rejects if some error occured). On success, the promise | ||
resolves to the new Job. | ||
jobId: number | string; // Override the job ID - by default, the job ID is a unique | ||
// integer, but you can use this setting to override it. | ||
// If you use this option, it is up to you to ensure the | ||
// jobId is unique. If you attempt to add a job with an id that | ||
// already exists, it will not be added. | ||
removeOnComplete: boolean; // If true, removes the job when it successfully | ||
// completes. Default behavior is to keep the job in the completed queue. | ||
} | ||
``` | ||
```typescript | ||
interface BackoffOpts{ | ||
type: string; // Backoff type, which can be either `fixed` or `exponential` | ||
delay: number; // Backoff delay, in milliseconds. | ||
} | ||
``` | ||
--------------------------------------- | ||
@@ -478,17 +488,17 @@ | ||
<a name="pause"/> | ||
#### Queue##pause([isLocal]) | ||
#### Queue##pause | ||
```ts | ||
pause(isLocal?: boolean): Promise | ||
``` | ||
Returns a promise that resolves when the queue is paused. A paused queue will not | ||
process new jobs until resumed, but current jobs being processed will continue until | ||
they are finalized. The pause can be either global or local. If global, all workers in all queue instances for a given queue will be paused. If local, just this worker will stop processing new jobs after the current lock expires. This can be useful to stop a worker from taking new jobs prior to shutting down. | ||
they are finalized. The pause can be either global or local. If global, all workers | ||
in all queue instances for a given queue will be paused. If local, just this worker will | ||
stop processing new jobs after the current lock expires. This can be useful to stop a | ||
worker from taking new jobs prior to shutting down. | ||
Pausing a queue that is already paused does nothing. | ||
__Arguments__ | ||
```javascript | ||
isLocal {Boolean} True to only pause the local worker. Defaults to false. | ||
returns {Promise} A promise that resolves when the queue is paused. | ||
``` | ||
--------------------------------------- | ||
@@ -498,3 +508,6 @@ | ||
<a name="resume"/> | ||
#### Queue##resume([isLocal]) | ||
#### Queue##resume | ||
```ts | ||
resume(isLocal?: boolean): Promise | ||
``` | ||
@@ -509,9 +522,2 @@ Returns a promise that resolves when the queue is resumed after being paused. | ||
__Arguments__ | ||
```javascript | ||
isLocal {Boolean} True to resume only the local worker. Defaults to false. | ||
returns {Promise} A promise that resolves when the queue is resumed. | ||
``` | ||
--------------------------------------- | ||
@@ -521,31 +527,30 @@ | ||
<a name="count"/> | ||
#### Queue##count() | ||
#### Queue##count | ||
```ts | ||
count(): Promise<number> | ||
``` | ||
Returns a promise that returns the number of jobs in the queue, waiting or | ||
paused. Since there may be other processes adding or processing jobs, this | ||
delayed. Since there may be other processes adding or processing jobs, this | ||
value may be true only for a very small amount of time. | ||
__Arguments__ | ||
```javascript | ||
returns {Promise} A promise that resolves with the current jobs count. | ||
``` | ||
--------------------------------------- | ||
<a name="empty"/> | ||
#### Queue##empty() | ||
#### Queue##empty | ||
```ts | ||
empty(): Promise | ||
``` | ||
Empties a queue deleting all the input lists and associated jobs. | ||
__Arguments__ | ||
```javascript | ||
returns {Promise} A promise that resolves with the queue is emptied. | ||
``` | ||
--------------------------------------- | ||
<a name="close"/> | ||
#### Queue##close() | ||
#### Queue##close | ||
```ts | ||
close(): Promise | ||
``` | ||
Closes the underlying redis client. Use this to perform a graceful | ||
@@ -595,29 +600,43 @@ shutdown. | ||
__Arguments__ | ||
```javascript | ||
returns {Promise} A promise that resolves when the redis client closes. | ||
``` | ||
--------------------------------------- | ||
<a name="getJob"/> | ||
#### Queue##getJob(jobId) | ||
#### Queue##getJob | ||
```ts | ||
getJob(jobId: string): Promise<Job> | ||
``` | ||
Returns a promise that will return the job instance associated with the `jobId` | ||
parameter. If the specified job cannot be located, the promise callback parameter | ||
will be set to `null`. | ||
parameter. If the specified job cannot be located, the promise will be resolved to `null`. | ||
__Arguments__ | ||
```javascript | ||
jobId {String} A string identifying the ID of the to look up. | ||
returns {Promise} A promise that resolves with the job instance when the job | ||
has been retrieved to the queue, or null otherwise. | ||
--------------------------------------- | ||
<a name="getJobCounts"/> | ||
#### Queue##getJobCounts | ||
```ts | ||
getJobCounts() : Promise<JobCounts> | ||
``` | ||
Returns a promise that will return the job counts for the given queue. | ||
```typescript{ | ||
interface JobCounts { | ||
wait: number, | ||
active: number, | ||
completed: number, | ||
failed: number, | ||
delayed: number | ||
} | ||
} | ||
``` | ||
--------------------------------------- | ||
<a name="clean"/> | ||
#### Queue##clean(grace, [type], [limit]) | ||
#### Queue##clean | ||
```ts | ||
clean(grace: number, status?: string, limit?: number): Promise<number[]> | ||
``` | ||
@@ -641,7 +660,8 @@ Tells the queue remove jobs of a specific type created outside of a grace period. | ||
```javascript | ||
grace {int} Grace period in milliseconds. | ||
type {string} type of job to clean. Values are completed, wait, active, | ||
grace: number; Grace period in milliseconds. | ||
status: string; Status of the job to clean. Values are completed, wait, active, | ||
delayed, and failed. Defaults to completed. | ||
limit {int} maximum amount of jobs to clean per call. If not provided will clean all matching jobs. | ||
returns {Promise} A promise that resolves with an array of removed jobs. | ||
limit: number; maximum amount of jobs to clean per call. If not provided will clean all matching jobs. | ||
returns Promise; A promise that resolves with an array of removed jobs. | ||
``` | ||
@@ -653,8 +673,4 @@ | ||
```javascript | ||
queue.on('cleaned', function (jobs, type) {}); | ||
jobs {Array} An array of jobs that have been cleaned. | ||
type {String} The type of job cleaned. Options are completed, wait, active, | ||
delayed, or failed. | ||
```typescript | ||
queue.on('cleaned', listener: (jobs: number[], status: string) => void); | ||
``` | ||
@@ -664,33 +680,2 @@ | ||
<a name="priorityQueue"/> | ||
###PriorityQueue(queueName, redisPort, redisHost, [redisOpts]) | ||
### DEPRECATION notice | ||
The priority queue has been deprecated since version 2.2.0 in favor of a new option, *priority* in [Queue##add](#add). | ||
The priorityQueue will be removed from the code base in version 3.0.0. | ||
-- | ||
This is the Queue constructor of priority queue. It works same a normal queue, with same function and parameters. | ||
The only difference is that the Queue#add() allow an options opts.priority that could take | ||
["low", "normal", "medium", "high", "critical"]. If no options provider, "normal" will be taken. | ||
The priority queue will process more often higher priority jobs than lower. | ||
```javascript | ||
var PriorityQueue = require("bull/lib/priority-queue"); | ||
var queue = new PriorityQueue("myPriorityQueues"); | ||
queue.add({todo: "Improve feature"}, {priority: "normal"}); | ||
queue.add({todo: "Read 9gags"}, {priority: "low"}); | ||
queue.add({todo: "Fix my test unit"}, {priority: "critical"}); | ||
queue.process(function(job, done) { | ||
console.log("I have to: " + job.data.todo); | ||
done(); | ||
}); | ||
``` | ||
Warning: Priority queue use 5 times more redis connections than a normal queue. | ||
<a name="job"/> | ||
@@ -709,40 +694,66 @@ ### Job | ||
<a name="remove"/> | ||
#### Job##remove() | ||
#### Job##remove | ||
```ts | ||
remove(): Promise | ||
``` | ||
Removes a Job from the queue from all the lists where it may be included. | ||
__Arguments__ | ||
```javascript | ||
returns {Promise} A promise that resolves when the job is removed. | ||
``` | ||
--------------------------------------- | ||
<a name="retry"/> | ||
#### Job##retry() | ||
#### Job##retry | ||
```ts | ||
retry(): Promise | ||
``` | ||
Rerun a Job that has failed. | ||
Re-run a Job that has failed. Returns a promise that resolves when the job is scheduled for retry. | ||
__Arguments__ | ||
```javascript | ||
returns {Promise} A promise that resolves when the job is scheduled for retry. | ||
``` | ||
--------------------------------------- | ||
<a name="discard"/> | ||
#### Job##discard() | ||
#### Job##discard | ||
```ts | ||
discard(): Promise | ||
``` | ||
Ensure this job is never ran again even if attemptsMade is less than `job.attempts` | ||
__Arguments__ | ||
--------------------------------------- | ||
<a name="priorityQueue"/> | ||
###PriorityQueue(queueName, redisPort, redisHost, [redisOpts]) | ||
### DEPRECATION notice | ||
The priority queue has been deprecated since version 2.2.0 in favor of a new option, *priority* in [Queue##add](#add). | ||
The priorityQueue will be removed from the code base in version 3.0.0. | ||
-- | ||
This is the Queue constructor of priority queue. It works same a normal queue, with same function and parameters. | ||
The only difference is that the Queue#add() allow an options opts.priority that could take | ||
["low", "normal", "medium", "high", "critical"]. If no options provider, "normal" will be taken. | ||
The priority queue will process more often higher priority jobs than lower. | ||
```javascript | ||
returns {Promise} A promise that resolves when the job is scheduled for retry. | ||
var PriorityQueue = require("bull/lib/priority-queue"); | ||
var queue = new PriorityQueue("myPriorityQueues"); | ||
queue.add({todo: "Improve feature"}, {priority: "normal"}); | ||
queue.add({todo: "Read 9gags"}, {priority: "low"}); | ||
queue.add({todo: "Fix my test unit"}, {priority: "critical"}); | ||
queue.process(function(job, done) { | ||
console.log("I have to: " + job.data.todo); | ||
done(); | ||
}); | ||
``` | ||
--------------------------------------- | ||
Warning!!: Priority queue use 5 times more redis connections than a normal queue. | ||
####Debugging | ||
@@ -749,0 +760,0 @@ |
@@ -1130,2 +1130,20 @@ /*eslint-env node */ | ||
it('should listen to global events', function(done){ | ||
var queue1 = utils.buildQueue(); | ||
var queue2 = utils.buildQueue(); | ||
queue1.process(function (job, jobDone) { | ||
jobDone(); | ||
}); | ||
queue1.add({}); | ||
queue2.once('global:waiting', function () { | ||
queue2.once('global:active', function () { | ||
queue2.once('global:completed', function () { | ||
queue1.close().then(function(){ | ||
queue2.close().then(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}) | ||
describe('Delayed jobs', function () { | ||
@@ -1132,0 +1150,0 @@ var queue; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
227162
5990
776