【问题标题】:Resque on Heroku Cedar not workingHeroku Cedar 上的 Resque 不起作用
【发布时间】:2012-06-13 15:35:08
【问题描述】:

几天来我一直在试图找出问题所在,但没有运气,我正在使用 Unicorn 在 Heroku Cedar 上运行 Rails 3.1.3,并使用 Resque 1.20 进行后台作业。

已添加 Redis 插件并设置了 REDISTOGO_URL,我将 resque.rb 初始化程序设置为

require 'resque'
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS

我也试过

Resque.redis = Redis.connect(:url => ENV['REDISTOGO_URL'])

还有这个,来自 RedisToGo 官方网站

ENV["REDISTOGO_URL"] ||= "redis://username:password@host:1234/"

uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password,     :thread_safe => true)

Heroku 工作者为:

bundle exec rake resque:work QUEUE='*'

在本地和 Heroku 控制台中一切正常;但是当我尝试从 Rails 排队时

Resque.enqueue(EmailQueue, id)

我明白了

NoMethodError (undefined method `sadd' for nil:NilClass):

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby heroku redis resque


    【解决方案1】:

    想通了,因为我在独角兽;我必须如下设置 config/unicorn.rb 来连接或 Redis。

    after_fork do |server, worker|
     # Replace with MongoDB or whatever
      if defined?(ActiveRecord::Base)
         ActiveRecord::Base.establish_connection
         Rails.logger.info('Connected to ActiveRecord')
      end
    
    # If you are using Redis but not Resque, change this
     if defined?(Resque)
        Resque.redis = ENV['REDISTOGO_URL']
        Rails.logger.info('Connected to Redis')
     end
    end
    

    希望这对其他人有所帮助。

    【讨论】:

    • 谢谢,这是我下班后的解决方案!
    猜你喜欢
    • 1970-01-01
    • 2011-10-24
    • 2011-10-04
    • 1970-01-01
    • 2012-07-11
    • 2016-08-05
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    相关资源
    最近更新 更多