From 9c2ec6610ae5efe924397f0e46ef787a25ccc0ba Mon Sep 17 00:00:00 2001 From: Evan Tahler Date: Tue, 19 Sep 2017 09:05:51 -0700 Subject: [PATCH] allow for empty namespaces --- README.md | 2 +- changelog | 3 ++- lib/connection.js | 1 + lib/queue.js | 1 + test/core/connection.js | 9 +++++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 33c6fe8a..3af16a61 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Build Status](https://secure.travis-ci.org/taskrabbit/node-resque.png?branch=master)](http://travis-ci.org/taskrabbit/node-resque) ## Version Notes -* ‼️ Version 6+ of Node Resque uses async/await. There is no upgrade path from previous versions. Node v8.0.0+ is required. +* ‼️ Version 5+ of Node Resque uses async/await. There is no upgrade path from previous versions. Node v8.0.0+ is required. ## Usage diff --git a/changelog b/changelog index e745321c..abdd5e1c 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ - dropped support for fakeredis; you must use a redis connection which supports promises - async!!! - capitol names for all classes -- plugin lifecycles are now cammel case: beforeEnqueue, afterEnqueue, beforePerform, afterPerform +- plugin lifecycles are now camel case: beforeEnqueue, afterEnqueue, beforePerform, afterPerform - plugin lifecycle methods are now async methods, with no callback - plugins now inherit from NodeResque.Plugin +- allow for empty/null namespaces (to match sidekiq's default) diff --git a/lib/connection.js b/lib/connection.js index d06e25e6..d0705bfa 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -81,6 +81,7 @@ class Connection extends EventEmitter { let args args = (arguments.length >= 1 ? [].slice.call(arguments, 0) : []) args.unshift(this.options.namespace) + args = args.filter((e) => { return String(e).trim() }) return args.join(':') } } diff --git a/lib/queue.js b/lib/queue.js index b62929c0..fa71b20d 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -185,6 +185,7 @@ class Queue extends EventEmitter { for (var i = 0; i < keys.length; i++) { var k = keys[i] k = k.replace(this.connection.key(''), '') + if (k[0] === ':') { k = k.substr(1) } data[k] = values[i] } diff --git a/test/core/connection.js b/test/core/connection.js index 14731d24..ba47ee06 100644 --- a/test/core/connection.js +++ b/test/core/connection.js @@ -45,4 +45,13 @@ describe('connection', () => { connection.key('thing').should.equal(specHelper.namespace + ':thing') connection.end() }) + + it('removes empty namespace from generated key', async () => { + let connectionDetails = specHelper.cleanConnectionDetails() + connectionDetails['namespace'] = '' + let connection = new NodeResque.Connection(connectionDetails) + await connection.connect() + connection.key('thing').should.equal('thing') + connection.end() + }) })