Thursday, 15 July 2010

ruby - Connection Pool returning an instance of Redis and not ConnectionPool -



ruby - Connection Pool returning an instance of Redis and not ConnectionPool -

i trying create rails app utilize resque managing workers. but, go on using connectionpool gem.

i have in initializer:

puts env["redistogo_url"] uri = (not env["redistogo_url"].nil?) ? uri.parse(env["redistogo_url"]) : nil # @ point, debugger confirms $redis nil $redis = connectionpool::wrapper.new(:size => 5, :timeout => 3) { if uri.nil? redis.connect else redis.connect(:host => uri.host, :port => uri.port, :password => uri.password) end } $redis # set in here debugger # @ point, $redis #<redis:0x007fb1b0036bf0> # when should instance of connectionpool::wrapper

does have thought why $redis not returned instance connectionpool::wrapper?

i've searched in gems source code, set value of $redis. in connectionpool's source code, did not find homecoming instance of redis instead of itself.

this happens when switched delayedjob resque. so, seem problem. however, i'm @ loss.

i using unicorn. here's file in config.

worker_processes 2 timeout 30 preload_app true before_fork |server, worker| # replace mongodb or whatever if defined?(activerecord::base) activerecord::base.connection.disconnect! rails.logger.info('disconnected activerecord') end # if using redis not resque, alter if defined?(resque) resque.redis.quit rails.logger.info('disconnected redis') end sleep 1 end after_fork |server, worker| # replace mongodb or whatever if defined?(activerecord::base) activerecord::base.establish_connection rails.logger.info('connected activerecord') end # if using redis not resque, alter if defined?(resque) # yes, commented resque out debugging, still same problem. #resque.redis = env['redistogo_url'] rails.logger.info('connected redis') end end

and finally, procfile:

web: bundle exec unicorn -p $port -c ./config/unicorn.rb worker: env term_child=1 queue=* bundle exec rake resque:work

i'm using foreman in develop environment.

any help appreciated.

from docs:

you can utilize connectionpool::wrapper wrap single global connection.

i looks connectionpool::wrapper meant wrap single connection redis convenience migrating big applications using redis straight using connectionpools

if phone call $redis.with, #with defined connectionpool

to actual connection pool, alter your

connectionpool::wrapper.new(:size => 5, :timeout => 3) { #redis logic }

to

connectionpool.new(:size => 5, :timeout => 3) { #redis logic }

ruby ruby-on-rails-3 redis

No comments:

Post a Comment