-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resque-multi-job-forks recovered + refactoring
- Loading branch information
Showing
2 changed files
with
41 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# coding: utf-8 | ||
|
||
namespace :resque do | ||
# Здесь мы добавляем некоторые необходимые для корректной работы "хуки". | ||
# | ||
# @see https://github.com/resque/resque/tree/1-x-stable#workers | ||
task :setup => :environment do | ||
# 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_fork { ActiveRecord::Base.connection_handler.clear_all_connections! } | ||
|
||
# Нужно также закрыть соединение к memcache | ||
Resque.before_fork { Rails.cache.reset if Rails.cache.respond_to?(:reset) } | ||
|
||
# Support for resque-multi-job-forks | ||
if ENV['JOBS_PER_FORK'] || ENV['MINUTES_PER_FORK'] | ||
require 'resque-multi-job-forks' | ||
end | ||
end | ||
end |