diff --git a/lib/resque/integration.rb b/lib/resque/integration.rb index cba9221..74c2eab 100644 --- a/lib/resque/integration.rb +++ b/lib/resque/integration.rb @@ -8,7 +8,6 @@ require 'resque-rails' require 'active_record' -require 'resque-ensure-connected' require 'active_support/concern' diff --git a/lib/resque/integration/tasks/hooks.rake b/lib/resque/integration/tasks/hooks.rake index 5ec7107..ce64f38 100644 --- a/lib/resque/integration/tasks/hooks.rake +++ b/lib/resque/integration/tasks/hooks.rake @@ -10,28 +10,27 @@ namespace :resque do # слушать HUP сигнал для ротации логов Resque::Integration::LogsRotator.register_hup_signal - # Reestablish Redis connection for each fork - # Tested on both redis-2.2.x and redis-3.0.x - # - # @see https://groups.google.com/forum/#!msg/ror2ru/CV96h5OGDxY/IqZbRsl-BcIJ - Resque.before_fork { Resque.redis.client.disconnect } - Resque.after_fork { Resque.redis.client.connect } - # Нужно закрыть все соединения в **родительском** процессе, - # все остальное делает гем `resque-ensure-connected`. - # - # Вообще, он делает буквально следующее: - # Resque.after_fork { ActiveRecord::Base.connection_handler.verify_active_connections! } - # - # Это работает - Resque.before_first_fork { ActiveRecord::Base.connection_handler.clear_all_connections! } - # Нужно также закрыть соединение к memcache - Resque.before_first_fork { Rails.cache.reset if Rails.cache.respond_to?(:reset) } - - # Красиво нарисуем название процесса + Resque.before_first_fork do + ActiveRecord::Base.connection_handler.clear_all_connections! + Rails.cache.reset if Rails.cache.respond_to?(:reset) + end + + Resque.before_fork do + Resque.redis.client.disconnect + end + Resque.after_fork do |job| $0 = "resque-#{Resque::Version}: Processing #{job.queue}/#{job.payload['class']} since #{Time.now.to_s(:db)}" + + if ActiveRecord::VERSION::MAJOR >= 4 + ActiveRecord::Base.clear_active_connections! + else + ActiveRecord::Base.verify_active_connections! + end + + Resque.redis.client.connect end # Support for resque-multi-job-forks diff --git a/resque-integration.gemspec b/resque-integration.gemspec index ea2e683..ba19286 100644 --- a/resque-integration.gemspec +++ b/resque-integration.gemspec @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'resque/integration/version' @@ -18,8 +18,8 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'resque', '= 1.25.2' gem.add_runtime_dependency 'railties', '>= 3.0.0' + gem.add_runtime_dependency 'activerecord', '>= 3.0.0' gem.add_runtime_dependency 'resque-rails', '>= 1.0.1' - gem.add_runtime_dependency 'resque-ensure-connected', '>= 0.2.0' # reconnect after fork gem.add_runtime_dependency 'resque-lock', '~> 1.1.0' gem.add_runtime_dependency 'resque-meta', '>= 2.0.0' gem.add_runtime_dependency 'resque-progress', '~> 1.0.1'