From 4213ebcbaa76f4ef7f5d4fcc0bbbebb4a9fd3eb5 Mon Sep 17 00:00:00 2001 From: lykmapipo Date: Tue, 14 Apr 2015 09:14:32 +0300 Subject: [PATCH] adding expiration key generator and subscribe to key expiry events --- index.js | 24 ++++++++++++++++++++++-- test/capability.spec.js | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 288b9b9..f7b59cf 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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... }; diff --git a/test/capability.spec.js b/test/capability.spec.js index 308f78c..d247434 100644 --- a/test/capability.spec.js +++ b/test/capability.spec.js @@ -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() { @@ -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(); + }); + }); \ No newline at end of file