Skip to content

Commit

Permalink
fix(redis): use ioredis to store configs (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-fox authored and r3rastogi committed Aug 22, 2017
1 parent c3a5429 commit dc2c2b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Executor = require('screwdriver-executor-base');
const Redis = require('ioredis');
const Resque = require('node-resque');
const fuses = require('circuit-fuses');
const Breaker = fuses.breaker;
Expand Down Expand Up @@ -30,13 +31,19 @@ class ExecutorQueue extends Executor {

const redisConnection = Object.assign({}, config.redisConnection, { pkg: 'ioredis' });

this.redis = new Redis(
redisConnection.port,
redisConnection.host,
redisConnection.options
);

// eslint-disable-next-line new-cap
this.queue = new Resque.queue({ connection: redisConnection });
this.queueBreaker = new Breaker((funcName, ...args) =>
this.queue[funcName](...args), breaker);
this.redisBreaker = new Breaker((funcName, ...args) =>
// Use the queue's built-in connection to send redis commands instead of instantiating a new one
this.queue.connection.redis[funcName](...args), breaker);
this.redis[funcName](...args), breaker);

this.fuseBox = new FuseBox();
this.fuseBox.addFuse(this.queueBreaker);
Expand Down
18 changes: 11 additions & 7 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('index test', () => {
let executor;
let resqueMock;
let queueMock;
let redisMock;
let redisConstructorMock;

before(() => {
mockery.enable({
Expand All @@ -33,18 +35,20 @@ describe('index test', () => {
enqueue: sinon.stub().yieldsAsync(),
del: sinon.stub().yieldsAsync(null, 1),
connection: {
connected: false,
redis: {
hdel: sinon.stub().yieldsAsync(),
hset: sinon.stub().yieldsAsync()
}
connected: false
}
};
resqueMock = {
queue: sinon.stub().returns(queueMock)
};
redisMock = {
hdel: sinon.stub().yieldsAsync(),
hset: sinon.stub().yieldsAsync()
};
redisConstructorMock = sinon.stub().returns(redisMock);

mockery.registerMock('node-resque', resqueMock);
mockery.registerMock('ioredis', redisConstructorMock);

/* eslint-disable global-require */
Executor = require('../index');
Expand Down Expand Up @@ -128,7 +132,7 @@ describe('index test', () => {
token: 'asdf'
}).then(() => {
assert.calledOnce(queueMock.connect);
assert.calledWith(queueMock.connection.redis.hset, 'buildConfigs', testConfig.buildId,
assert.calledWith(redisMock.hset, 'buildConfigs', testConfig.buildId,
JSON.stringify(testConfig));
assert.calledWith(queueMock.enqueue, 'builds', 'start', [partialTestConfig]);
}));
Expand Down Expand Up @@ -169,7 +173,7 @@ describe('index test', () => {
}).then(() => {
assert.calledOnce(queueMock.connect);
assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfig]);
assert.calledWith(queueMock.connection.redis.hdel, 'buildConfigs', 8609);
assert.calledWith(redisMock.hdel, 'buildConfigs', 8609);
assert.notCalled(queueMock.enqueue);
}));

Expand Down

0 comments on commit dc2c2b4

Please sign in to comment.