Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/http/public/javascripts/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ Job.prototype.renderUpdate = function () {

// delayed
if ('delayed' == this.state) {
var delay = parseInt(this.delay, 10)
, creation = parseInt(this.created_at, 10)
var delay = this.delay
, creation = this.created_at
, remaining = relative(creation + delay - Date.now());
view.title((this.data.title || '') + ' <em>( ' + remaining + ' )</em>');
}
Expand Down
18 changes: 9 additions & 9 deletions lib/queue/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ exports.get = function( id, jobType, fn ) {
// we can just merge these
job.type = hash.type;
job._ttl = hash.ttl;
job._delay = hash.delay;
job._delay = parseInt(hash.delay, 10);
job.priority(Number(hash.priority));
job._progress = hash.progress;
job._attempts = Number(hash.attempts);
job._max_attempts = Number(hash.max_attempts);
job._state = hash.state;
job._error = hash.error;
job.created_at = hash.created_at;
job.promote_at = hash.promote_at;
job.updated_at = hash.updated_at;
job.failed_at = hash.failed_at;
job.started_at = hash.started_at;
job.created_at = parseInt(hash.created_at, 10);
job.promote_at = parseInt(hash.promote_at, 10);
job.updated_at = parseInt(hash.updated_at, 10);
job.failed_at = parseInt(hash.failed_at, 10);
job.started_at = parseInt(hash.started_at, 10);
job.duration = hash.duration;
job.workerId = hash.workerId;
job._removeOnComplete = hash.removeOnComplete;
Expand Down Expand Up @@ -692,7 +692,7 @@ Job.prototype.state = function( state, fn ) {
.zadd(client.getKey('jobs:' + this.type + ':' + state), this._priority, this.zid);

// use promote_at as score when job moves to delayed
('delayed' === state) ? multi.zadd(client.getKey('jobs:' + state), parseInt(this.promote_at), this.zid) : noop();
('delayed' === state) ? multi.zadd(client.getKey('jobs:' + state), this.promote_at, this.zid) : noop();
('active' === state && this._ttl > 0) ? multi.zadd(client.getKey('jobs:' + state), Date.now() + parseInt(this._ttl), this.zid) : noop();
('active' === state && !this._ttl) ? multi.zadd(client.getKey('jobs:' + state), this._priority<0?this._priority:-this._priority, this.zid) : noop();
('inactive' === state) ? multi.lpush(client.getKey(this.type + ':jobs'), 1) : noop();
Expand Down Expand Up @@ -839,8 +839,8 @@ Job.prototype.update = function( fn ) {
if( this._delay ) {
this.set('delay', this._delay);
if( this.created_at ) {
var timestamp = parseInt(this.failed_at || this.created_at, 10)
, delay = parseInt(this._delay);
var timestamp = this.failed_at || this.created_at
, delay = this._delay;
this.promote_at = timestamp + delay;
this.set('promote_at', this.promote_at);
}
Expand Down
69 changes: 69 additions & 0 deletions test/tdd/kue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,75 @@ describe('Kue', function () {
});
});

describe('Function: save', function () {
var queue;
var client;

beforeEach(function () {
client = {
incr: sinon.stub().callsArgWith(1, null, 1),
getKey: sinon.stub().returns([]),
createFIFO: sinon.stub().returns(1),
sadd: sinon.stub()
};
queue = kue.createQueue();
Job.client = client;
});

it('should set created_at when job saved', function (done) {
var now = Date.now();
var job = queue.create('type', {});
job.subscribe = sinon.stub().callsArg(0);
job.set = sinon.stub();
job.update = sinon.stub().callsArg(0);

job.save(function () {
job.created_at.should.be.approximately(now, 200);
done();
});
});
});

describe('Function: get', function () {
var client;
var createClient;

beforeEach(function () {
client = {
getKey: sinon.stub().returns([]),
createFIFO: sinon.stub().returns(1),
hgetall: sinon.stub().callsArgWith(1, null, {
created_at: '12345',
failed_at: '12345',
promote_at: '12345',
delay: '12345',
updated_at: '12345',
started_at: '12345',
type: 'type'
})
};
createClient = redis.createClient;
redis.createClient = sinon.stub().returns(client);
});

afterEach(function () {
redis.createClient = createClient;
redis._client = null;
});

it('should convert date fields to numbers', function (done) {
Job.get(1, 'type', function (err, job) {
job.created_at.should.be.an.instanceOf(Number);
job.failed_at.should.be.an.instanceOf(Number);
job.promote_at.should.be.an.instanceOf(Number);
job._delay.should.be.an.instanceOf(Number);
job.updated_at.should.be.an.instanceOf(Number);
job.started_at.should.be.an.instanceOf(Number);
done();
});
});
});

describe('Function: on', function() {
var queue, noop;
beforeEach(function(){
Expand Down