diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 0ccdd512d..eb3d07756 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -130,7 +130,7 @@ HELP end end end - end + ende def deprecate_hoptoad_api_key if self[:hoptoad_api_key].present? @@ -170,4 +170,24 @@ HELP def self.single_process_mode? (ENV['SINGLE_PROCESS'] == "true" || ENV['SINGLE_PROCESS_MODE'] == "true" || self[:single_process_mode]) ? true : false 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 diff --git a/config/application.yml.example b/config/application.yml.example index 54abba54c..6c1c8f47b 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -24,10 +24,13 @@ defaults: &defaults ## Examples, uncomment one or add your own: 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! - ## Leave it empty for the default (localhost) - redis_url: '' + ## Leave it empty for the default ('redis://localhost:6379/0') + ## 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. ## This is highly not recommended for production use, diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 910ba2079..c89f86723 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -3,19 +3,7 @@ require 'resque' Resque::Plugins::Timeout.timeout = 300 if !AppConfig.single_process_mode? - if redis_to_go = ENV["REDISTOGO_URL"] - 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 + Resque.redis = AppConfig.get_redis_instance end # Single process-mode hooks using Resque.inline diff --git a/config/unicorn.rb b/config/unicorn.rb index 7d943d226..7c6810b7e 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -47,12 +47,7 @@ after_fork do |server, worker| # copy pasta from resque.rb because i'm a bad person if !AppConfig.single_process_mode? - if redis_to_go = ENV["REDISTOGO_URL"] - 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 + Resque.redis = AppConfig.get_redis_instance end # Enable this line to have the workers run as different user/group