简体   繁体   English

使用Heroku在RedisToGo上使用Resque,Resque Server

[英]Resque, Resque Server, on RedisToGo with Heroku

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: LIB /任务/ 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: routes.rb中:

  mount Resque::Server.new, :at => "/resque" 

initializers: redis.rb: 初始化程序: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: 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? 我觉得我在这里转圈,有什么想法吗?

I think your Procfile has a typo. 我认为您的Procfile有拼写错误。 Why do you have two web processes? 为什么你有两个web流程? I'd stick with one and use unicorn . 我会坚持使用独角兽

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. 使用带有resque的 独角兽时,每次独角兽分叉时都必须定义resque redis连接。 Here are the relevant files. 这是相关文件。

config/initializers/redis.rb 配置/初始化/ 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.rb

Resque.redis = REDIS_WORKER

config/unicorn.rb 配置/ 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,请参阅此要点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM