Skip to content

Commit

Permalink
Merge pull request #1 from Buzzertech/fix/remove-publisher
Browse files Browse the repository at this point in the history
Fix/remove publisher
  • Loading branch information
Buzzertech committed Oct 7, 2018
2 parents 79afc9e + e228329 commit 731b98e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
17 changes: 2 additions & 15 deletions src/Pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
let subscriber: any;
let publisher: any;

export default new class PubSub {
init (Subscriber: any, Publisher: any) {
init (Subscriber: any) {
if (typeof Subscriber === undefined) {
throw new Error ('Please provide a new redis instance for subscribe')
}

if (typeof Publisher === undefined) {
throw new Error ('Please provide a new redis instance for publisher')
}

subscriber = Subscriber;
publisher = Publisher;
}

publish(channel: string, message: string) {
if (typeof publisher.publish === undefined) {
throw new Error('The provided redis client doesn\'t supports publishing messages');
}
publisher.publish(channel, message);
}

subscribe(channel: string) {
if (typeof publisher.subscribe === undefined) {
if (typeof subscriber.subscribe === undefined) {
throw new Error('The provided redis client doesn\'t supports subscribing to messages');
}

Expand Down
8 changes: 1 addition & 7 deletions src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export interface IQueueOpts {
redis: any;
/** A separate instance of redis to subscribe to events internally */
subscriberRedis: any;
/** A separate instance of redis to publish events internally */
publisherRedis: any;
/** Default retries is set to 4 */
maxRetries?: number;
}
Expand All @@ -34,11 +32,7 @@ export class Queue {
throw new Error('Subscriber Redis Client Not provided');
}

if (typeof this.opts.publisherRedis === undefined) {
throw new Error('Publisher Redis Client Not Provided');
}

Pubsub.init(this.opts.subscriberRedis, this.opts.publisherRedis);
Pubsub.init(this.opts.subscriberRedis);
}

public registerNamespace(namespace: string, handler: (namespace:string, ctx: any) => any): any {
Expand Down
21 changes: 0 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ describe('JerryQuu', () => {
let testEmailQueue;
const redis = Redis.createClient();
const subscriberRedis = sinon.stub(Redis.createClient());
const publisherRedis = Redis.createClient();


beforeEach(function () {
const transport = Nodemailer.createTransport({
Expand All @@ -23,7 +21,6 @@ describe('JerryQuu', () => {
testEmailQueue = new EmailQueue({
redis,
subscriberRedis,
publisherRedis,
maxRetries: 2,
transport: transport
});
Expand All @@ -47,7 +44,6 @@ describe('JerryQuu', () => {
try {
new EmailQueue({
redis: redis,
publisherRedis: Redis.createClient(),
maxRetries: 2,
transport: Nodemailer.createTransport({
host: '127.0.0.1',
Expand All @@ -59,22 +55,6 @@ describe('JerryQuu', () => {
}
});

it('throws an error if publisher redis instance not passed', () => {
try {
new EmailQueue({
redis: redis,
subscriberRedis: Redis.createClient(),
maxRetries: 2,
transport: Nodemailer.createTransport({
host: '127.0.0.1',
port: '587'
})
});
} catch (err) {
expect(err.message).to.equal('Publisher Redis Client Not Provided');
}
});

it('throw an error if namespace not provided', () => {
try {
testEmailQueue.registerNamespace();
Expand Down Expand Up @@ -157,7 +137,6 @@ describe('JerryQuu', () => {
it('set custom maxRetries', () => {
const emailQueue = new EmailQueue({
maxRetries: 5,
publisherRedis: publisherRedis,
subscriberRedis: subscriberRedis,
redis: redis,
transport: Nodemailer.createTransport({
Expand Down

0 comments on commit 731b98e

Please sign in to comment.