Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from apartmentlist/upstream-prep
Browse files Browse the repository at this point in the history
Ensure Resque Redis instance gets restored in all cases
  • Loading branch information
rpdillon committed May 7, 2015
2 parents ddd91b2 + dcfbd4c commit 6a3e157
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.mdown
Expand Up @@ -110,13 +110,15 @@ Note: This subscribes when this class is loaded, so it needs to be in your load

### Dedicated Redis Instance

By default, Resque-Bus uses the same instance of Redis as Resque. If desired, Resque-Bus can be configured to use a different instance. In your initializer:
By default, Resque Bus uses the same instance of Redis as Resque. If desired, Resque-Bus can be configured to use a different instance. In your initializer:

```ruby
QueueBus.adapter.redis = 'redis://my-other-redis-host:1234/4'
```

Resque-Bus accepts the same types of Redis server descriptions as Resque.
Resque Bus accepts the same types of Redis server descriptions as Resque.

Once that instance variable is set, Resque Bus tasks will default to using it, including both the driver and the queuebus consumers. All the commands described below will 'just work' as written, including subscribe, unsubscribe, driver, and worker.

### Commands

Expand Down
15 changes: 9 additions & 6 deletions lib/resque_bus/adapter.rb
Expand Up @@ -29,12 +29,15 @@ def queuebus_redis

# Save the default Resque redis connection
default_redis = ::Resque.redis
# Get Resque to generate the connection given the server definition
::Resque.redis = @queuebus_redis_url
# Store the Redis namespace that Resque created...
@queuebus_redis = ::Resque.redis
# ...and restore the default.
::Resque.redis = default_redis
begin
# Get Resque to generate the connection given the server definition
::Resque.redis = @queuebus_redis_url
# Store the Redis namespace that Resque created...
@queuebus_redis = ::Resque.redis
ensure
# ...and restore the default.
::Resque.redis = default_redis
end
@queuebus_redis
else
::Resque.redis
Expand Down
5 changes: 2 additions & 3 deletions spec/adapter_spec.rb
Expand Up @@ -32,20 +32,19 @@
context 'with a custom QueueBus Redis configuration' do
let(:resque_url) { 'redis://localhost:6379/0' }
let(:queuebus_url) { 'redis://localhost:6379/1' }
let(:active_url) { ::Resque.redis.redis.client.options[:url] }

before(:each) do
Resque.redis = resque_url
QueueBus.adapter.redis = queuebus_url
end

it 'still uses the default for Resque jobs' do
active_url.should eq(resque_url)
::Resque.redis.redis.client.options[:url].should eq(resque_url)
end

it 'uses the custom Redis instance for QueueBus jobs' do
QueueBus.adapter.redis do
active_url.should eq(queuebus_url)
::Resque.redis.redis.client.options[:url].should eq(queuebus_url)
end
end

Expand Down

0 comments on commit 6a3e157

Please sign in to comment.