Comparing version 3.0.0 to 3.1.0
@@ -0,1 +1,10 @@ | ||
v.3.1.0 | ||
======= | ||
- Added rate limiter support. | ||
- Added method to update jobs data. | ||
- Implemented stalled as global event. | ||
[Changes](https://github.com/OptimalBits/bull/compare/v3.0.0...v3.1.0) | ||
v.3.0.0 | ||
@@ -2,0 +11,0 @@ ======= |
@@ -102,2 +102,6 @@ /*eslint-env node */ | ||
Job.prototype.update = function(data){ | ||
return this.queue.client.hset(this.queue.toKey(this.id), 'data', JSON.stringify(data)); | ||
}; | ||
Job.prototype.toJSON = function(){ | ||
@@ -104,0 +108,0 @@ var opts = Object.assign({}, this.opts); |
@@ -54,3 +54,2 @@ /*eslint-env node */ | ||
var MINIMUM_REDIS_VERSION = '2.8.18'; | ||
var MAX_TIMEOUT_MS = Math.pow(2, 31) - 1; // 32 bit signed | ||
@@ -61,3 +60,4 @@ | ||
prefix?: string = 'bull', | ||
redis : RedisOpts, // ioredis defaults | ||
limiter?: RateLimiter, | ||
redis : RedisOpts, // ioredis defaults, | ||
createClient?: (type: enum('client', 'subscriber'), redisOpts?: RedisOpts) => redisClient, | ||
@@ -75,2 +75,7 @@ | ||
} | ||
interface RateLimiter { | ||
max: number, // Number of jobs | ||
duration: number, // per duration milliseconds | ||
} | ||
*/ | ||
@@ -99,2 +104,6 @@ | ||
if(opts.limiter){ | ||
this.limiter = opts.limiter; | ||
} | ||
this.name = name; | ||
@@ -210,3 +219,4 @@ this.token = uuid(); | ||
'stalled', | ||
'repeat'], function(key){ | ||
'repeat', | ||
'limiter'], function(key){ | ||
keys[key] = _this.toKey(key); | ||
@@ -330,2 +340,3 @@ }); | ||
var activeKey = _this.toKey('active'); | ||
var stalledKey = _this.toKey('stalled'); | ||
var progressKey = _this.toKey('progress'); | ||
@@ -353,2 +364,7 @@ var delayedKey = _this.toKey('delayed'); | ||
break; | ||
case stalledKey: | ||
if(_this.token === token){ | ||
_this.emit('stalled', message); | ||
} | ||
_this.emit('global:stalled', message); | ||
} | ||
@@ -398,3 +414,3 @@ }); | ||
var channel = this.toKey(_eventName); | ||
if(_eventName === 'active' || _eventName === 'waiting'){ | ||
if(['active', 'waiting', 'stalled'].indexOf(_eventName) !== -1) { | ||
registering = this.registeredEvents[_eventName] = this.eclient.psubscribe(channel + '*'); | ||
@@ -424,7 +440,2 @@ } else { | ||
Queue.prototype.whenCurrentMoveFinished = function(){ | ||
var currentMove = this.client.commandQueue.peekFront(); | ||
return currentMove && currentMove.command.promise || Promise.resolve(); | ||
}; | ||
Queue.prototype.disconnect = function(){ | ||
@@ -431,0 +442,0 @@ // TODO: Only quit clients that we "own". |
@@ -79,2 +79,4 @@ /** | ||
keys[4] = queueKeys.stalled; | ||
keys[5] = queueKeys.limiter; | ||
keys[6] = queueKeys.delayed; | ||
@@ -89,2 +91,5 @@ var args = [ | ||
if(queue.limiter){ | ||
args.push(queue.limiter.max, queue.limiter.duration); | ||
} | ||
return queue.client.moveToActive(keys.concat(args)).then(function(result){ | ||
@@ -91,0 +96,0 @@ if(result){ |
{ | ||
"name": "bull", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Job manager", | ||
@@ -31,3 +31,3 @@ "main": "./lib/queue", | ||
"coveralls": "^2.13.1", | ||
"eslint": "^2.13.1", | ||
"eslint": "^4.4.1", | ||
"expect.js": "^0.3.1", | ||
@@ -34,0 +34,0 @@ "istanbul": "^0.4.5", |
@@ -76,2 +76,3 @@ | ||
- [x] Schedule and repeat jobs according to a cron specification. | ||
- [x] Rate limiter for jobs. | ||
- [x] Retries. | ||
@@ -87,4 +88,4 @@ - [x] Priority. | ||
- [ ] Job completion acknowledgement. | ||
- [ ] Rate limiter for jobs. | ||
- [ ] Parent-child jobs relationships. | ||
- [ ] Threaded processing functions. | ||
@@ -120,3 +121,4 @@ --- | ||
| Delayed jobs | ✓ | ✓ | | ✓ | | ||
| Global events | ✓ | | | | | ||
| Global events | ✓ | ✓ | | | | ||
| Rate Limiter | ✓ | | | | | ||
| Pause/Resume | ✓ | ✓ | | | | ||
@@ -123,0 +125,0 @@ | Repeatable jobs | ✓ | | | ✓ | |
@@ -29,2 +29,4 @@ | ||
- [Job](#job) | ||
- [Job#progress](#jobprogress) | ||
- [Job#update](#jobupdate) | ||
- [Job#remove](#jobremove) | ||
@@ -34,2 +36,4 @@ - [Job#retry](#jobretry) | ||
- [Job#promote](#jobpromote) | ||
- [Job#finished](#jobfinished) | ||
- [Events](#events) | ||
@@ -54,2 +58,3 @@ | ||
interface QueueOpts{ | ||
limiter?: RateLimiter; | ||
redis?: RedisOpts; | ||
@@ -61,2 +66,9 @@ prefix?: string = 'bull'; // prefix for all queue keys. | ||
```typescript | ||
interface RateLimiter { | ||
max: number, // Max number of jobs processed | ||
duration: number, // per duration in milliseconds | ||
} | ||
``` | ||
```RedisOpts``` are passed directly to ioredis constructor, check [ioredis](https://github.com/luin/ioredis/blob/master/API.md) | ||
@@ -493,4 +505,28 @@ for details. We document here just the most important ones. | ||
### Job#progress | ||
```ts | ||
progress(progress: number): Promise | ||
``` | ||
Updates a job progress. | ||
**Arguments** | ||
```js | ||
progress: number; Job progress between 0 and 100. | ||
``` | ||
--- | ||
### Job#update | ||
```ts | ||
update(data: object): Promise | ||
``` | ||
Updated a job data field with the give data object. | ||
--- | ||
### Job#remove | ||
@@ -536,3 +572,13 @@ | ||
### Job#finished | ||
```ts | ||
finished(): Promise | ||
``` | ||
Returns a promise that resolves or rejects when the job completes or fails. | ||
--- | ||
Events | ||
@@ -539,0 +585,0 @@ ------ |
@@ -86,2 +86,16 @@ /*eslint-env node */ | ||
describe('.update', function(){ | ||
it('should allow updating job data', function(){ | ||
return Job.create(queue, {foo: 'bar'}).then(function(job){ | ||
return job.update({baz: 'qux'}).then(function(){ | ||
return job; | ||
}); | ||
}).then(function(job){ | ||
return Job.fromId(queue, job.id).then(function(job){ | ||
expect(job.data).to.be.eql({baz: 'qux'}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('.remove', function () { | ||
@@ -88,0 +102,0 @@ it('removes the job from redis', function(){ |
@@ -16,3 +16,3 @@ /*eslint-env node */ | ||
describe.only('repeat', function () { | ||
describe('repeat', function () { | ||
var queue; | ||
@@ -19,0 +19,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
493192
67
5686
367