0

I'm running an app on heroku. The web worker is developed in the Grape framework.

As Grape doesn't have anything like config/initializers, I'm running a code like this before each access to 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)

After a while the Resque worker stops picking up jobs from Redis, even though some are queued there. When running locally everything works fine.

Any idea what am I doing wrong? Or where should I put the Resque's Redis initialization?

4

1 回答 1

0

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

  • :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 应用程序的文档不多。

于 2013-09-17T23:17:40.580 回答