【问题标题】:Resque losing connection to redis on herokuResque 在heroku 上失去与redis 的连接
【发布时间】:2013-09-14 03:50:57
【问题描述】:

我正在 Heroku 上运行一个应用程序。 Web Worker 是在 Grape 框架中开发的。

由于 Grape 没有配置/初始化程序之类的东西,所以我在每次访问 Resque 之前运行这样的代码:

HEROKU_REDIS_URL = "redis://redistogo:XXXXX@squawfish.redistogo.com:9990/"
uri = URI.parse(HEROKU_REDIS_URL)
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password, :thread_safe => false)

一段时间后,Resque 工作人员停止从 Redis 获取作业,即使其中一些已在那里排队。在本地运行时一切正常。

知道我做错了什么吗?或者我应该把 Resque 的 Redis 初始化放在哪里?

【问题讨论】:

  • Resque 版本请 :)
  • 这是 Resque 1.24.1,Redis 3.0.4

标签: heroku redis resque grape


【解决方案1】:

所以经过几个小时的调试后,我让它工作了。让我分享一下我的设置中有哪些错误:

  • :thread_safe => true:Redis 实例应该被创建为线程安全的。不确定在这种情况下它意味着什么,在 Redis 源代码中没有找到任何东西,但这就是他们建议的内容:http://redistogo.com/documentation/resque
  • 确保为 Web 服务器和工作进程仅将 redis 分配给 Resque 一次:我最终得到了这样的代码:

      require 'resque'
      if ENV["REDIS_SERVICE"]
        begin
          Resque.redis.get('abc')
        rescue Redis::CannotConnectError
          HEROKU_REDIS_URL = "redis://redistogo:XXXXX@squawfish.redistogo.com:9990/"
    
          uri = URI.parse(HEROKU_REDIS_URL)
          Resque.redis = Redis.new(
            :host => uri.host,
            :port => uri.port,
            :password => uri.password)
    
        end
      end
    

    我将它放在 app/resque_redis_init.rb 中,并且在 web 应用程序和 resque:setup 任务中的 worker Rakefile 中都需要

  • 确保没有人在使用同一个 Redis 服务器:我发现另一个 heroku 应用程序中的工作人员已经为 resque 设置了这个 redis,并且一直在队列中吃掉作业。工人配置错误,作业在我没有注意到的情况下失败了
  • 确保您的 Redis 中没有垃圾:我必须清除 Redis 的全部内容以确保没有错误的工人注册。
  • 确保您在正确的队列中排队作业,并且这些作业具有正确的优先级对我来说,这是 Procfile 中的以下设置

    resque: TERM_CHILD=1 VERBOSE=1 QUEUES=activity,polling bundle exec rake jobs:work
    

通过这种设置,它可以很好地工作。希望它对某人有所帮助,因为非 Rails 应用程序的文档不多。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    • 2014-04-19
    相关资源
    最近更新 更多