Skip to content

Commit

Permalink
fix(hooks): verify connections for rails 4x
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Nov 19, 2014
1 parent 66329ba commit 4713fb2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/resque/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'resque-rails'

require 'active_record'
require 'resque-ensure-connected'

require 'active_support/concern'

Expand Down
35 changes: 17 additions & 18 deletions lib/resque/integration/tasks/hooks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resque-integration.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit 4713fb2

Please sign in to comment.