From e12bf878faf16c2db50ee353285d72f5afc1e623 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 14 Feb 2014 09:43:34 -0500 Subject: [PATCH 1/3] Replaced class and instance level `send` Replaced with `__send__` from std lib * `send` can now be overridden to be more semantically meaningful * `message.send(user_id)` as opposed to `message.send_message(user_id)` * `__send__` makes it clear that the reflective version is intended --- lib/sidekiq/actor.rb | 6 +++--- lib/sidekiq/api.rb | 2 +- lib/sidekiq/extensions/action_mailer.rb | 2 +- lib/sidekiq/extensions/active_record.rb | 2 +- lib/sidekiq/extensions/class_methods.rb | 4 ++-- lib/sidekiq/rails.rb | 2 +- test/test_cli.rb | 12 ++++++------ test/test_client.rb | 4 ++-- test/test_exception_handler.rb | 8 ++++---- test/test_redis_connection.rb | 2 +- test/test_retry.rb | 10 +++++----- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/sidekiq/actor.rb b/lib/sidekiq/actor.rb index 64a7ab36..970ce93e 100644 --- a/lib/sidekiq/actor.rb +++ b/lib/sidekiq/actor.rb @@ -28,10 +28,10 @@ module Sidekiq def self.included(klass) if $TESTING - klass.send(:include, InstanceMethods) - klass.send(:extend, ClassMethods) + klass.__send__(:include, InstanceMethods) + klass.__send__(:extend, ClassMethods) else - klass.send(:include, Celluloid) + klass.__send__(:include, Celluloid) end end end diff --git a/lib/sidekiq/api.rb b/lib/sidekiq/api.rb index a5fa7932..b4331780 100644 --- a/lib/sidekiq/api.rb +++ b/lib/sidekiq/api.rb @@ -203,7 +203,7 @@ module Sidekiq end def [](name) - @item.send(:[], name) + @item.__send__(:[], name) end end diff --git a/lib/sidekiq/extensions/action_mailer.rb b/lib/sidekiq/extensions/action_mailer.rb index 3d6518ed..18469e72 100644 --- a/lib/sidekiq/extensions/action_mailer.rb +++ b/lib/sidekiq/extensions/action_mailer.rb @@ -14,7 +14,7 @@ module Sidekiq def perform(yml) (target, method_name, args) = YAML.load(yml) - msg = target.send(method_name, *args) + msg = target.__send__(method_name, *args) # The email method can return nil, which causes ActionMailer to return # an undeliverable empty message. msg.deliver if msg && (msg.to || msg.cc || msg.bcc) && msg.from diff --git a/lib/sidekiq/extensions/active_record.rb b/lib/sidekiq/extensions/active_record.rb index 34bae5f4..24b38dbc 100644 --- a/lib/sidekiq/extensions/active_record.rb +++ b/lib/sidekiq/extensions/active_record.rb @@ -16,7 +16,7 @@ module Sidekiq def perform(yml) (target, method_name, args) = YAML.load(yml) - target.send(method_name, *args) + target.__send__(method_name, *args) end end diff --git a/lib/sidekiq/extensions/class_methods.rb b/lib/sidekiq/extensions/class_methods.rb index bc1b4ad6..bdab2da4 100644 --- a/lib/sidekiq/extensions/class_methods.rb +++ b/lib/sidekiq/extensions/class_methods.rb @@ -14,7 +14,7 @@ module Sidekiq def perform(yml) (target, method_name, args) = YAML.load(yml) - target.send(method_name, *args) + target.__send__(method_name, *args) end end @@ -36,4 +36,4 @@ module Sidekiq end end -Module.send(:include, Sidekiq::Extensions::Klass) +Module.__send__(:include, Sidekiq::Extensions::Klass) diff --git a/lib/sidekiq/rails.rb b/lib/sidekiq/rails.rb index 42387d71..a6f495e8 100644 --- a/lib/sidekiq/rails.rb +++ b/lib/sidekiq/rails.rb @@ -1,7 +1,7 @@ module Sidekiq def self.hook_rails! if defined?(::ActiveRecord) - ::ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord) + ::ActiveRecord::Base.__send__(:include, Sidekiq::Extensions::ActiveRecord) end if defined?(::ActionMailer) diff --git a/test/test_cli.rb b/test/test_cli.rb index 997de5bc..a699cded 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -294,8 +294,8 @@ class TestCli < Sidekiq::Test describe 'when weight is present' do it 'concatenates queues by factor of weight and sets strict to false' do opts = { strict: true } - @cli.send :parse_queues, opts, [['often', 7], ['repeatedly', 3]] - @cli.send :parse_queues, opts, [['once']] + @cli.__send__ :parse_queues, opts, [['often', 7], ['repeatedly', 3]] + @cli.__send__ :parse_queues, opts, [['once']] assert_equal (%w[often] * 7 + %w[repeatedly] * 3 + %w[once]), opts[:queues] assert !opts[:strict] end @@ -304,8 +304,8 @@ class TestCli < Sidekiq::Test describe 'when weight is not present' do it 'returns queues and sets strict' do opts = { strict: true } - @cli.send :parse_queues, opts, [['once'], ['one_time']] - @cli.send :parse_queues, opts, [['einmal']] + @cli.__send__ :parse_queues, opts, [['once'], ['one_time']] + @cli.__send__ :parse_queues, opts, [['einmal']] assert_equal %w[once one_time einmal], opts[:queues] assert opts[:strict] end @@ -316,7 +316,7 @@ class TestCli < Sidekiq::Test describe 'when weight is present' do it 'concatenates queue to opts[:queues] weight number of times and sets strict to false' do opts = { strict: true } - @cli.send :parse_queue, opts, 'often', 7 + @cli.__send__ :parse_queue, opts, 'often', 7 assert_equal %w[often] * 7, opts[:queues] assert !opts[:strict] end @@ -325,7 +325,7 @@ class TestCli < Sidekiq::Test describe 'when weight is not present' do it 'concatenates queue to opts[:queues] once and leaves strict true' do opts = { strict: true } - @cli.send :parse_queue, opts, 'once', nil + @cli.__send__ :parse_queue, opts, 'once', nil assert_equal %w[once], opts[:queues] assert opts[:strict] end diff --git a/test/test_client.rb b/test/test_client.rb index b2f87c75..fd4f9a6c 100644 --- a/test/test_client.rb +++ b/test/test_client.rb @@ -226,11 +226,11 @@ class TestClient < Sidekiq::Test describe 'item normalization' do it 'defaults retry to true' do - assert_equal true, Sidekiq::Client.new.send(:normalize_item, 'class' => QueuedWorker, 'args' => [])['retry'] + assert_equal true, Sidekiq::Client.new.__send__(:normalize_item, 'class' => QueuedWorker, 'args' => [])['retry'] end it "does not normalize numeric retry's" do - assert_equal 2, Sidekiq::Client.new.send(:normalize_item, 'class' => CWorker, 'args' => [])['retry'] + assert_equal 2, Sidekiq::Client.new.__send__(:normalize_item, 'class' => CWorker, 'args' => [])['retry'] end end end diff --git a/test/test_exception_handler.rb b/test/test_exception_handler.rb index 43bd388a..58a7ea65 100644 --- a/test/test_exception_handler.rb +++ b/test/test_exception_handler.rb @@ -59,7 +59,7 @@ class TestExceptionHandler < Sidekiq::Test end after do - Object.send(:remove_const, "Airbrake") # HACK should probably inject Airbrake etc into this class in the future + Object.__send__(:remove_const, "Airbrake") # HACK should probably inject Airbrake etc into this class in the future end it "notifies Airbrake" do @@ -75,7 +75,7 @@ class TestExceptionHandler < Sidekiq::Test end after do - Object.send(:remove_const, "Honeybadger") # HACK should probably inject Honeybadger etc into this class in the future + Object.__send__(:remove_const, "Honeybadger") # HACK should probably inject Honeybadger etc into this class in the future end it "notifies Honeybadger" do @@ -91,7 +91,7 @@ class TestExceptionHandler < Sidekiq::Test end after do - Object.send(:remove_const, "ExceptionNotifier") + Object.__send__(:remove_const, "ExceptionNotifier") end it "notifies ExceptionNotifier" do @@ -120,7 +120,7 @@ class TestExceptionHandler < Sidekiq::Test end after do - Object.send(:remove_const, "Exceptional") + Object.__send__(:remove_const, "Exceptional") end it "notifies Exceptional" do diff --git a/test/test_redis_connection.rb b/test/test_redis_connection.rb index bebf78a1..1fadded8 100644 --- a/test/test_redis_connection.rb +++ b/test/test_redis_connection.rb @@ -77,7 +77,7 @@ class TestRedisConnection < Sidekiq::Test ENV[v] = nil end ENV[var] = uri - assert_equal uri, Sidekiq::RedisConnection.send(:determine_redis_provider) + assert_equal uri, Sidekiq::RedisConnection.__send__(:determine_redis_provider) ENV[var] = nil end diff --git a/test/test_retry.rb b/test/test_retry.rb index 10fdba46..9de0ac87 100644 --- a/test/test_retry.rb +++ b/test/test_retry.rb @@ -210,7 +210,7 @@ class TestRetry < Sidekiq::Test end it 'calls worker.retries_exhausted after too many retries' do - assert_equal [1,2, "foo", "retried_method"], handler.send(:retries_exhausted, worker.new, msg) + assert_equal [1,2, "foo", "retried_method"], handler.__send__(:retries_exhausted, worker.new, msg) end end @@ -226,7 +226,7 @@ class TestRetry < Sidekiq::Test end it 'calls worker sidekiq_retries_exhausted_block after too many retries' do - new_msg = handler.send(:retries_exhausted, worker.new, msg) + new_msg = handler.__send__(:retries_exhausted, worker.new, msg) expected_msg = msg.merge('called_by_callback' => true) assert_equal expected_msg, new_msg, "sidekiq_retries_exhausted block not called" @@ -288,15 +288,15 @@ class TestRetry < Sidekiq::Test let(:handler) { Sidekiq::Middleware::Server::RetryJobs.new } it "retries with a default delay" do - refute_equal 4, handler.send(:delay_for, worker, 2) + refute_equal 4, handler.__send__(:delay_for, worker, 2) end it "retries with a custom delay" do - assert_equal 4, handler.send(:delay_for, custom_worker, 2) + assert_equal 4, handler.__send__(:delay_for, custom_worker, 2) end it "falls back to the default retry on exception" do - refute_equal 4, handler.send(:delay_for, error_worker, 2) + refute_equal 4, handler.__send__(:delay_for, error_worker, 2) assert_match(/Failure scheduling retry using the defined `sidekiq_retry_in`/, File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in') end From 315db463cf0867f7723c4326d532e6a699fdb3ab Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Sat, 15 Feb 2014 12:41:07 -0800 Subject: [PATCH 2/3] Automatically use config/sidekiq.yml if found, fixes #1481 --- Changes.md | 3 ++- lib/sidekiq/capistrano2.rb | 2 +- lib/sidekiq/cli.rb | 1 + lib/sidekiq/tasks/sidekiq.rake | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Changes.md b/Changes.md index 3fdfd4b8..73e89173 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,7 @@ -HEAD +2.17.5 ----------- +- Automatically use the config file found at `config/sidekiq.yml`, if not passed `-C`. [#1481] - Store 'retried\_at' and 'failed\_at' timestamps as Floats, not Strings. [#1473] - A `USR2` signal will now reopen _all_ logs, using IO#reopen. Thus, instead of creating a new Logger object, Sidekiq will now just update the existing Logger's file descriptor [#1163]. diff --git a/lib/sidekiq/capistrano2.rb b/lib/sidekiq/capistrano2.rb index 189d8fe9..85216a22 100644 --- a/lib/sidekiq/capistrano2.rb +++ b/lib/sidekiq/capistrano2.rb @@ -40,7 +40,7 @@ Capistrano::Configuration.instance.load do task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do rails_env = fetch(:rails_env, "production") for_each_process do |pid_file, idx| - run "cd #{current_path} ; nohup #{fetch(:sidekiq_cmd)} -e #{rails_env} -C #{current_path}/config/sidekiq.yml -i #{idx} -P #{pid_file} >> #{current_path}/log/sidekiq.log 2>&1 &", :pty => false + run "cd #{current_path} ; nohup #{fetch(:sidekiq_cmd)} -e #{rails_env} -i #{idx} -P #{pid_file} >> #{current_path}/log/sidekiq.log 2>&1 &", :pty => false end end diff --git a/lib/sidekiq/cli.rb b/lib/sidekiq/cli.rb index 05cadcb1..f6364a0d 100644 --- a/lib/sidekiq/cli.rb +++ b/lib/sidekiq/cli.rb @@ -299,6 +299,7 @@ module Sidekiq die 1 end @parser.parse!(argv) + opts[:config_file] ||= 'config/sidekiq.yml' if File.exist?('config/sidekiq.yml') opts end diff --git a/lib/sidekiq/tasks/sidekiq.rake b/lib/sidekiq/tasks/sidekiq.rake index 4737341d..6f457f4e 100644 --- a/lib/sidekiq/tasks/sidekiq.rake +++ b/lib/sidekiq/tasks/sidekiq.rake @@ -15,7 +15,7 @@ namespace :load do set :sidekiq_pid, ->{ "tmp/sidekiq.pid" } # "-d -i INT -P PATH" are added automatically. - set :sidekiq_options, ->{ "-e #{fetch(:rails_env, 'production')} -C #{current_path}/config/sidekiq.yml -L #{current_path}/log/sidekiq.log" } + set :sidekiq_options, ->{ "-e #{fetch(:rails_env, 'production')} -L #{current_path}/log/sidekiq.log" } set :sidekiq_timeout, ->{ 10 } set :sidekiq_role, ->{ :app } From e79cfa550473b37fec43933c62272b022f1f04a4 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Sat, 15 Feb 2014 12:56:27 -0800 Subject: [PATCH 3/3] 1.4.3 release --- Pro-Changes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Pro-Changes.md b/Pro-Changes.md index 6f79574a..2ae548f0 100644 --- a/Pro-Changes.md +++ b/Pro-Changes.md @@ -3,10 +3,11 @@ Sidekiq Pro Changelog Please see [http://sidekiq.org/pro](http://sidekiq.org/pro) for more details and how to buy. -HEAD +1.4.3 ----------- - Reverse sorting of Batches in Web UI [#1098] +- Refactoring for Sidekiq 3.0, Pro now requires Sidekiq 2.17.5 1.4.2 -----------