I've been trying to get Resque (with Resque server) & RedisToGo working on heroku (cedar) for awhile now, but I keep running into this error:
我一直试图让Resque(使用Resque服务器)和RedisToGo在heroku(雪松)上工作一段时间,但我一直遇到这个错误:
Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)):
Its working locally, and I can access redis just fine in Heroku's console for my app.
它在本地工作,我可以在我的应用程序的Heroku控制台中访问redis。
My Procfile has:
我的Procfile有:
web: bundle exec thin start -p $PORT -e $RACK_ENV
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
resque: env TERM_CHILD=1 RESQUE_TERM_TIMEOUT=10 bundle exec rake resque:work
My Gemfile has:
我的Gemfile有:
gem 'redis'
#Background queue
gem 'resque', '~> 1.22.0', :require => "resque/server"
lib/tasks/resque.rake:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
routes.rb:
mount Resque::Server.new, :at => "/resque"
initializers: redis.rb:
uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS
resque.rb:
Dir["#{Rails.root}/app/workers/*.rb"].each { |file| require file }
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
then in my app/workers directory I have something like myjob.rb
然后在我的app / workers目录中,我有类似myjob.rb的东西
I feel like I'm going in circles here, any ideas?
我觉得我在这里转圈,有什么想法吗?
1 个解决方案
#1
8
I think your Procfile
has a typo. Why do you have two web
processes? I'd stick with one and use unicorn.
我认为您的Procfile有拼写错误。为什么你有两个网络流程?我坚持使用一个并使用独角兽。
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
web:bundle exec unicorn -p $ PORT -c ./config/unicorn.rb
When using unicorn with resque, you have to define the resque redis connection each time unicorn forks. Here are the relevant files.
当使用具有resque的独角兽时,您必须在每次独角兽分叉时定义resque redis连接。这是相关文件。
config/initializers/redis.rb
uri = URI.parse(ENV["REDIS_WORKER"])
REDIS_WORKER = Redis.new(host: uri.host, port: uri.port, password: uri.password)
config/initializers/resque.rb
Resque.redis = REDIS_WORKER
config/unicorn.rb
before_fork do |server, worker|
if defined?(Resque)
Resque.redis.quit
Rails.logger.info("Disconnected from Redis")
end
end
after_fork do |server, worker|
if defined?(Resque)
Resque.redis = REDIS_WORKER
Rails.logger.info("Connected to Redis")
end
end
See this gist for the complete unicorn.rb
请参阅此要点以获取完整的unicorn.rb
#1
8
I think your Procfile
has a typo. Why do you have two web
processes? I'd stick with one and use unicorn.
我认为您的Procfile有拼写错误。为什么你有两个网络流程?我坚持使用一个并使用独角兽。
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
web:bundle exec unicorn -p $ PORT -c ./config/unicorn.rb
When using unicorn with resque, you have to define the resque redis connection each time unicorn forks. Here are the relevant files.
当使用具有resque的独角兽时,您必须在每次独角兽分叉时定义resque redis连接。这是相关文件。
config/initializers/redis.rb
uri = URI.parse(ENV["REDIS_WORKER"])
REDIS_WORKER = Redis.new(host: uri.host, port: uri.port, password: uri.password)
config/initializers/resque.rb
Resque.redis = REDIS_WORKER
config/unicorn.rb
before_fork do |server, worker|
if defined?(Resque)
Resque.redis.quit
Rails.logger.info("Disconnected from Redis")
end
end
after_fork do |server, worker|
if defined?(Resque)
Resque.redis = REDIS_WORKER
Rails.logger.info("Connected to Redis")
end
end
See this gist for the complete unicorn.rb
请参阅此要点以获取完整的unicorn.rb