node-resque
Advanced tools
Comparing version 5.4.0 to 5.4.1
const path = require('path') | ||
const Ioredis = require('ioredis') | ||
const specHelper = require(path.join(__dirname, '..', 'utils', 'specHelper.js')) | ||
@@ -44,7 +45,70 @@ const NodeResque = require(path.join(__dirname, '..', '..', 'index.js')) | ||
test('will properly build namespace strings', async () => { | ||
let connection = new NodeResque.Connection(specHelper.cleanConnectionDetails()) | ||
await connection.connect() | ||
expect(connection.key('thing')).toBe(specHelper.namespace + ':thing') | ||
connection.end() | ||
describe('keys and namespaces', () => { | ||
const db = specHelper.connectionDetails.database | ||
let connection | ||
beforeAll(async () => { | ||
connection = new NodeResque.Connection(specHelper.cleanConnectionDetails()) | ||
await connection.connect() | ||
}) | ||
let prefixedConnection | ||
let prefixedRedis | ||
beforeAll(async () => { | ||
prefixedRedis = new Ioredis({keyPrefix: 'customNamespace:', db: db}) | ||
prefixedConnection = new NodeResque.Connection({redis: prefixedRedis, namespace: specHelper.namespace}) | ||
await prefixedConnection.connect() | ||
}) | ||
afterAll(async () => { | ||
connection.end() | ||
prefixedConnection.end() | ||
prefixedRedis.quit() | ||
}) | ||
test('keys built with the default namespace are correct', () => { | ||
expect(connection.key('thing')).toBe(`resque-test-${db}:thing`) | ||
expect(prefixedConnection.key('thing')).toBe(`resque-test-${db}:thing`) | ||
// the value retunred by a redis prefix should match a plain redis connection | ||
expect(connection.key('thing')).toBe(prefixedConnection.key('thing')) | ||
}) | ||
test('ioredis transparent key prefix writes keys with the prefix even if they are not returned', async () => { | ||
await connection.redis.set(connection.key('testPrefixKey'), 'abc123') | ||
await prefixedConnection.redis.set(prefixedConnection.key('testPrefixKey'), 'abc123') | ||
const result = await connection.redis.get(connection.key('testPrefixKey')) | ||
const prefixedResult = await prefixedConnection.redis.get(prefixedConnection.key('testPrefixKey')) | ||
expect(result).toBe('abc123') | ||
expect(prefixedResult).toBe('abc123') | ||
const keys = await connection.redis.keys('*') | ||
expect(keys).toContain(`resque-test-${db}:testPrefixKey`) | ||
expect(keys).toContain(`customNamespace:resque-test-${db}:testPrefixKey`) | ||
}) | ||
test('keys built with a custom namespace are correct', () => { | ||
connection.options.namespace = 'customNamespace' | ||
expect(connection.key('thing')).toBe(`customNamespace:thing`) | ||
prefixedConnection.options.namespace = 'customNamespace' | ||
expect(prefixedConnection.key('thing')).toBe(`customNamespace:thing`) | ||
}) | ||
test('keys built with a array namespace are correct', () => { | ||
connection.options.namespace = ['custom', 'namespace'] | ||
expect(connection.key('thing')).toBe(`custom:namespace:thing`) | ||
prefixedConnection.options.namespace = ['custom', 'namespace'] | ||
expect(prefixedConnection.key('thing')).toBe(`custom:namespace:thing`) | ||
}) | ||
test('will properly build namespace strings dynamically', async () => { | ||
connection.options.namespace = specHelper.namespace | ||
expect(connection.key('thing')).toBe(specHelper.namespace + ':thing') | ||
prefixedConnection.options.namespace = specHelper.namespace | ||
expect(prefixedConnection.key('thing')).toBe(specHelper.namespace + ':thing') | ||
expect(connection.key('thing')).toBe(prefixedConnection.key('thing')) | ||
}) | ||
}) | ||
@@ -51,0 +115,0 @@ |
@@ -483,3 +483,3 @@ const path = require('path') | ||
test('can remove stuck workers and re-enquue thier jobs', async () => { | ||
test('can remove stuck workers and re-enqueue their jobs', async () => { | ||
let age = 1 | ||
@@ -486,0 +486,0 @@ await queue.enqueue(specHelper.queue, 'slowJob', {a: 1}) |
@@ -89,3 +89,7 @@ const EventEmitter = require('events').EventEmitter | ||
args = (arguments.length >= 1 ? [].slice.call(arguments, 0) : []) | ||
args.unshift(this.options.namespace) | ||
if (Array.isArray(this.options.namespace)) { | ||
args.unshift(...this.options.namespace) | ||
} else { | ||
args.unshift(this.options.namespace) | ||
} | ||
args = args.filter((e) => { return String(e).trim() }) | ||
@@ -92,0 +96,0 @@ return args.join(':') |
@@ -6,3 +6,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "5.4.0", | ||
"version": "5.4.1", | ||
"homepage": "http://github.com/taskrabbit/node-resque", | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -144,3 +144,3 @@ # node-resque: The best background jobs in node. | ||
database: 0, | ||
namespace: "resque", | ||
namespace: "resque", // Also allow array of strings | ||
} | ||
@@ -180,2 +180,3 @@ | ||
- This project implements the "scheduler" part of rescue-scheduler (the daemon which can promote enqueued delayed jobs into the work queues when it is time), but not the CRON scheduler proxy. To learn more about how to use a CRON-like scheduler, read the [Job Schedules](#job-schedules) section of this document. | ||
- "Namespace" is a string which is appended to the front of your keys in redis. Normally, it is "resque". This is helpful if you want to store multiple work queues in one redis database. Do not use `keyPrefix` if you are using the `ioredis` (default) redis driver in this project (see https://github.com/taskrabbit/node-resque/issues/245 for more information.) | ||
- If you are using any plugins which effect `beforeEnqueue` or `afterEnqueue`, be sure to pass the `jobs` argument to the `new NodeResque.Queue()` constructor | ||
@@ -182,0 +183,0 @@ - If a job fails, it will be added to a special `failed` queue. You can then inspect these jobs, write a plugin to manage them, move them back to the normal queues, etc. Failure behavior by default is just to enter the `failed` queue, but there are many options. Check out these examples from the ruby ecosystem for inspiration: |
533400
3756
498