From 92c61e7601f4dc5d22f78985ca4eac48e39f6c58 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Tue, 3 Apr 2012 20:00:20 -0700 Subject: [PATCH] Cap fix, fixes #106 --- Changes.md | 3 ++- lib/sidekiq/capistrano.rb | 4 ++-- lib/sidekiq/redis_connection.rb | 3 ++- test/test_stats.rb | 30 ++++++++++++++++-------------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Changes.md b/Changes.md index aefcb5cc..7a93782d 100644 --- a/Changes.md +++ b/Changes.md @@ -2,7 +2,8 @@ HEAD ----------- - Fix fetch breaking retry when used with Redis namespaces. [#109] - +- Redis connection now just a plain ConnectionPool, not CP::Wrapper. +- Capistrano initial deploy fix [#106] 0.11.0 ----------- diff --git a/lib/sidekiq/capistrano.rb b/lib/sidekiq/capistrano.rb index 696b818c..344bd52e 100644 --- a/lib/sidekiq/capistrano.rb +++ b/lib/sidekiq/capistrano.rb @@ -8,12 +8,12 @@ Capistrano::Configuration.instance.load do desc "Quiet sidekiq (stop accepting new work)" task :quiet do - run "cd #{current_path} && bundle exec sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid" + run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid ; fi" end desc "Stop sidekiq" task :stop do - run "cd #{current_path} && bundle exec sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout}" + run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout} ; fi" end desc "Start sidekiq" diff --git a/lib/sidekiq/redis_connection.rb b/lib/sidekiq/redis_connection.rb index ab625e44..3a2ef5ad 100644 --- a/lib/sidekiq/redis_connection.rb +++ b/lib/sidekiq/redis_connection.rb @@ -6,7 +6,8 @@ module Sidekiq class RedisConnection def self.create(options={}) url = options[:url] || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0' - ConnectionPool::Wrapper.new(:timeout => 1, :size => (options[:size] || Sidekiq.options[:concurrency] || 25)) do + size = (options[:size] || Sidekiq.options[:concurrency] || 25) + ConnectionPool.new(:timeout => 1, :size => size) do build_client(url, options[:namespace]) end end diff --git a/test/test_stats.rb b/test/test_stats.rb index 88b4c565..bd1be3da 100644 --- a/test/test_stats.rb +++ b/test/test_stats.rb @@ -55,23 +55,25 @@ class TestStats < MiniTest::Unit::TestCase msg = { 'class' => DumbWorker.to_s, 'args' => [nil] } boss = MiniTest::Mock.new - assert_equal [], @redis.smembers('workers') - assert_equal 0, @redis.get('stat:failed').to_i - assert_equal 0, @redis.get('stat:processed').to_i + @redis.with do |conn| + assert_equal [], conn.smembers('workers') + assert_equal 0, conn.get('stat:failed').to_i + assert_equal 0, conn.get('stat:processed').to_i - processor = Sidekiq::Processor.new(boss) - assert_equal 1, @redis.smembers('workers').size + processor = Sidekiq::Processor.new(boss) + assert_equal 1, conn.smembers('workers').size - pstr = processor.to_s - assert_raises RuntimeError do - processor.process(msg, 'xyzzy') + pstr = processor.to_s + assert_raises RuntimeError do + processor.process(msg, 'xyzzy') + end + + set = conn.smembers('workers') + assert_equal 0, set.size + assert_equal 1, conn.get('stat:failed').to_i + assert_equal 1, conn.get('stat:processed').to_i + assert_equal nil, conn.get("stat:processed:#{pstr}") end - - set = @redis.smembers('workers') - assert_equal 0, set.size - assert_equal 1, @redis.get('stat:failed').to_i - assert_equal 1, @redis.get('stat:processed').to_i - assert_equal nil, @redis.get("stat:processed:#{pstr}") end end