Skip to content

Commit

Permalink
adding expiration key generator and subscribe to key expiry events
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Apr 14, 2015
1 parent f745a1b commit 4213ebc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var redis = kue.redis;
var _ = require('lodash');
var async = require('async');
var datejs = require('date.js');

// var uuid = require('node-uuid');
/**
* @constructor
* @description A job scheduling utility for kue
Expand Down Expand Up @@ -35,9 +35,29 @@ function KueScheduler(options) {

//a redis client to listen for key expiry
this.listener = redis.createClientFactory(this.options);

//subscribe to key expiration events
this.listener.subscribe('__keyevent@0__:expired');
}

/**
* @function
* @description generate an expiration key that is used to track job scheduling
* @private
*/
KueScheduler.prototype._getJobExpiryKey = function(uuid) {
return 'kue:scheduler:' + uuid;
};

/**
* @function
* @description generate a storage key for the scheduled job data
* @private
*/
KueScheduler.prototype._getJobDataKey = function(uuid) {
return 'kue:scheduler:data:' + uuid;
};


KueScheduler.prototype.every = function( /*interval, jobDefinition*/ ) {
// body...
};
Expand Down
19 changes: 19 additions & 0 deletions test/capability.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//dependencies
var expect = require('chai').expect;
var path = require('path');
var uuid = require('node-uuid');
var KueScheduler = require(path.join(__dirname, '..', 'index'));

describe('KueScheduler#Capability', function() {
Expand Down Expand Up @@ -33,4 +34,22 @@ describe('KueScheduler#Capability', function() {
done();
});

it('should be able to generate job expriration key', function(done) {
var jobuuid = uuid.v1();

expect(kueScheduler._getJobExpiryKey(jobuuid))
.to.be.equal('kue:scheduler:' + jobuuid);

done();
});

it('should be able to generate job data storage key', function(done) {
var jobuuid = uuid.v1();

expect(kueScheduler._getJobDataKey(jobuuid))
.to.be.equal('kue:scheduler:data:' + jobuuid);

done();
});

});

0 comments on commit 4213ebc

Please sign in to comment.