Unify redis initialization
REDISTOGO_URL is now deprecated in favor of REDIS_URL which is supported by the redis gem too.
This commit is contained in:
parent
f1631084d3
commit
48dcccf7b3
4 changed files with 29 additions and 23 deletions
|
|
@ -130,7 +130,7 @@ HELP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
ende
|
||||||
|
|
||||||
def deprecate_hoptoad_api_key
|
def deprecate_hoptoad_api_key
|
||||||
if self[:hoptoad_api_key].present?
|
if self[:hoptoad_api_key].present?
|
||||||
|
|
@ -170,4 +170,24 @@ HELP
|
||||||
def self.single_process_mode?
|
def self.single_process_mode?
|
||||||
(ENV['SINGLE_PROCESS'] == "true" || ENV['SINGLE_PROCESS_MODE'] == "true" || self[:single_process_mode]) ? true : false
|
(ENV['SINGLE_PROCESS'] == "true" || ENV['SINGLE_PROCESS_MODE'] == "true" || self[:single_process_mode]) ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.get_redis_instance
|
||||||
|
if ENV["REDISTOGO_URL"].present?
|
||||||
|
puts "WARNING: using the REDISTOGO_URL environment variable is deprecated, please use REDIS_URL now."
|
||||||
|
ENV['REDIS_URL'] = ENV["REDISTOGO_URL"]
|
||||||
|
end
|
||||||
|
|
||||||
|
redis_options = {}
|
||||||
|
|
||||||
|
if ENV['REDIS_URL'].present?
|
||||||
|
redis_options = { :url => ENV['REDIS_URL'] }
|
||||||
|
elsif ENV['RAILS_ENV']== 'integration2'
|
||||||
|
redis_options = { :host => 'localhost', :port => 6380 }
|
||||||
|
elsif AppConfig[:redis_url].present?
|
||||||
|
puts "WARNING: You're redis_url doesn't start with redis://" unless AppConfig[:redis_url].start_with?("redis://")
|
||||||
|
redis_options = { :url => AppConfig[:redis_url] }
|
||||||
|
end
|
||||||
|
|
||||||
|
Redis.new(redis_options.merge(:thread_safe => true))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,13 @@ defaults: &defaults
|
||||||
## Examples, uncomment one or add your own:
|
## Examples, uncomment one or add your own:
|
||||||
ca_file: '/etc/pki/tls/certs/ca-bundle.crt'
|
ca_file: '/etc/pki/tls/certs/ca-bundle.crt'
|
||||||
|
|
||||||
## URL for a remote redis, on the default port.
|
## Redis URL for a remote redis.
|
||||||
## Don't forget to restrict IP access!
|
## Don't forget to restrict IP access!
|
||||||
## Leave it empty for the default (localhost)
|
## Leave it empty for the default ('redis://localhost:6379/0')
|
||||||
redis_url: ''
|
## You can specify a username and password in it, for example
|
||||||
|
## redis://user:password@remote_host:6379/0
|
||||||
|
## You can also specify a unix socket URL like unix://tmp/redis.sock
|
||||||
|
redis_url:
|
||||||
|
|
||||||
## Serve static assets via the appserver.
|
## Serve static assets via the appserver.
|
||||||
## This is highly not recommended for production use,
|
## This is highly not recommended for production use,
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,7 @@ require 'resque'
|
||||||
Resque::Plugins::Timeout.timeout = 300
|
Resque::Plugins::Timeout.timeout = 300
|
||||||
|
|
||||||
if !AppConfig.single_process_mode?
|
if !AppConfig.single_process_mode?
|
||||||
if redis_to_go = ENV["REDISTOGO_URL"]
|
Resque.redis = AppConfig.get_redis_instance
|
||||||
uri = URI.parse(redis_to_go)
|
|
||||||
redis_options = { :host => uri.host, :port => uri.port,
|
|
||||||
:passsword => uri.password }
|
|
||||||
elsif ENV['RAILS_ENV']== 'integration2'
|
|
||||||
redis_options = { :host => 'localhost', :port => 6380 }
|
|
||||||
elsif AppConfig[:redis_url].present?
|
|
||||||
redis_options = { :url => AppConfig[:redis_url], :port => 6379 }
|
|
||||||
end
|
|
||||||
|
|
||||||
if redis_options
|
|
||||||
Resque.redis = Redis.new(redis_options.merge(:thread_safe => true))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Single process-mode hooks using Resque.inline
|
# Single process-mode hooks using Resque.inline
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,7 @@ after_fork do |server, worker|
|
||||||
|
|
||||||
# copy pasta from resque.rb because i'm a bad person
|
# copy pasta from resque.rb because i'm a bad person
|
||||||
if !AppConfig.single_process_mode?
|
if !AppConfig.single_process_mode?
|
||||||
if redis_to_go = ENV["REDISTOGO_URL"]
|
Resque.redis = AppConfig.get_redis_instance
|
||||||
uri = URI.parse(redis_to_go)
|
|
||||||
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
|
|
||||||
elsif AppConfig[:redis_url]
|
|
||||||
Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable this line to have the workers run as different user/group
|
# Enable this line to have the workers run as different user/group
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue