Sidekiq和Redis on heroku;如何最好地确保在Redis连接上进行每次调用并且没有错误

时间:2014-11-02 01:48:52

标签: ruby-on-rails exception heroku redis sidekiq

这是一个相当广泛的问题,但我不清楚哪个部分失败或如何使我的代码更有可能成功运行。

我在Heroku上有一个Rails应用程序,并且遇到了如下错误:

  

连接超时时出现异常

     

回溯:   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:269:in   write' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:269:in 写”   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:244:in   block in write' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:226:in IO”   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:243:in   进程中write' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:204:in 阻止(3个级别)   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:198:in   进程中each' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:198:in 阻止(2个级别)   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:329:in   ensure_connected' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:197:in 阻止进程'   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:279:in   logging' /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:196:in 过程   /app/vendor/bundle/ruby/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:102:in   `call'/app/vendor/bundle/ruby/2.1。

据推测,这是因为redistogo存在一些连接问题。进行这些运行至关重要,因为我们重新生成这些JSON片段和外部javascript文件,如果redistogo已关闭(或上述异常中发生的任何事情),则不会引发任何内容。具体来说,我只在15分钟后收到一封电子邮件。这是我第一次使用Sidekiq,确实需要立即收到警报。我怎么能达到这个目标呢?

这是被调用的worker类:​​

class CatalogWorker
  include Sidekiq::Worker

  sidekiq_options({
                      backtrace: true,

                      # Should be set to true (enables uniqueness for async jobs)
                      # or :all (enables uniqueness for both async and scheduled jobs)
                      unique: :true,

                      # Unique expiration (optional, default is 30 minutes)
                      # For scheduled jobs calculates automatically based on schedule time and expiration period
                      expiration: 24 * 60 * 60
                  })


  def perform catalog_id, current_user_id, app_event_id
    CatalogGenerator.build cat_id, current_user_id: current_user_id, job_id: jid, app_event_id: app_event_id  #, note: note, current_user_id: current_user_id
  end
end

和我的目录生成器

class CatalogGenerator

  def self.build id, note: "no note in calling", current_user_id: nil, job_id: "testme", app_event_id: nil, create_new_skq_current: true

    if app_event_id
      app_event=AppEvent.find(app_event_id)
      app_event_changes=app_event.attributes_changes
    else
      app_event_changes="UNKNOWN"
    end

    if current_user_id
      user=User.find(current_user_id)
      user_email=user.email
    else
      user_email="not sure"
    end
    mg_start=CatalogGenerationStart.index id, job_id, user_email
    mg_start.deliver

    # here's the part that matters
    begin
       CatalogGenerator.json_full(id)
    rescue => ex
      ecm=ExceptionCaughtMail.index ex, "CatalogGenerator.json_full with #{id}"
      ecm.deliver
    end

    begin
      CatalogGenerator.js_external(id)
    rescue => ex
      ecm=ExceptionCaughtMail.index ex, "CatalogGenerator.js_external with #{id}"
      ecm.deliver
    end

    begin
      CatalogGenerator.json(id)
    rescue => ex
      ecm=ExceptionCaughtMail.index ex, "CatalogGenerator.json with #{id}"
      ecm.deliver
    end

    begin
      CatalogImageGenerator.json(id)
    rescue => ex
      ecm=ExceptionCaughtMail.index ex, "CatalogImageGenerator.json with #{id}"
      ecm.deliver
    end
  end

0 个答案:

没有答案