ruby-on-rails - Resque worker 默默地死去

标签 ruby-on-rails ruby-on-rails-3 redis resque

我为网站设置的工作人员遇到问题。这是应用程序的一些背景: 它在 rails 3.0.2 上运行,使用 mongodb,redis gem 2.2.2。为了让 worker 保持正常运行,我设置了 god gem 并指定 6 个 worker 应该在生产环境中运行。我将在下面粘贴 resque.god.rb 文件。此外,还有一个专为 resque-workers 和 elasticsearch 服务设置的独特的 Ubuntu 服务器,因此它不共享任何其他服务。

我的问题是,出于任何原因,工作人员不断死去,只是在我的 log/resque-worker.log 文件中记录“*** Exiting ...”,这非常烦人,因为我不知道发生了什么上。它不会在 syslog 文件或 dmesg 中记录任何内容

这是我在日志中得到的一部分(对我没有帮助)

*** Starting worker workers:19166:*
*** Starting worker workers:19133:*
*** Running before_first_fork hook
*** Exiting...
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /data/www/tap-production/releases/20170904162514)
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Running before_first_fork hook
*** Exiting...
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /data/www/tap-production/releases/20170904162514)
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Starting worker workers:19251:*
*** Starting worker workers:19217:*
*** Running before_first_fork hook
*** Exiting...
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /data/www/tap-production/releases/20170904162514)
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Running before_first_fork hook
*** Exiting...
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /data/www/tap-production/releases/20170904162514)
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Starting worker workers:19330:*
*** Starting worker workers:19297:*
*** Running before_first_fork hook
*** Exiting...
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /data/www/tap-production/releases/20170904162514)
/usr/local/www/tap-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require': iconv will be deprecated in the future, use String#encode instead.

这是我的 resque.god.rb 代码:

require 'tlsmail'
rails_env = ENV['RAILS_ENV']
rails_root = ENV['RAILS_ROOT']
rake_root = ENV['RAKE_ROOT']
num_workers = rails_env == 'production' ? 6 : 1
# Change cache to my_killer_worker_job if you are testing in development. remember to enable it on config/resque_schedule.yml - Fabian
queue = rails_env == 'production' ? '*' : 'my_killer_worker_job'

God::Contacts::Email.defaults do |d|
  Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
  if rails_env == "production"
    #Change this settings for your own purposes
    d.from_name = "#{rails_env.upcase}: Process monitoring"
    d.delivery_method = :smtp
    d.server_host = 'smtp.gmail.com'
    d.server_port = 587
    d.server_auth = :login
    d.server_domain = 'gmail.com'
    d.server_user = 'XXXX@gmail.com'
    d.server_password = 'XXXX'
  end
end



God.contact(:email) do |c|
  c.name = 'engineering'
  c.group = 'developers'
  c.to_email = 'engineering@something.com'
end

num_workers.times do |num|
  God.watch do |w|
    w.name          = "resque-#{num}"
    w.group         = 'resque'
    w.interval      = 30.seconds
    w.env           = { 'RAILS_ENV' => rails_env, 'QUEUE' => queue, 'VERBOSE' => '1' }
    w.dir           = rails_root
    w.start         = "bundle exec #{rake_root}/rake resque:work"
    w.start_grace   = 10.seconds
    w.log           = File.join(rails_root, 'log', 'resque-worker.log')

    # restart if memory gets too high
    w.transition(:up, :restart) do |on|
      on.condition(:memory_usage) do |c|
        c.above = 200.megabytes
        c.times = 2
        # c.notify = 'engineering'
      end
    end

    # determine the state on startup
    w.transition(:init, { true => :up, false => :start }) do |on|
      on.condition(:process_running) do |c|
        c.running = true
        # c.notify = 'engineering'
      end
    end

    # determine when process has finished starting
    w.transition([:start, :restart], :up) do |on|
      on.condition(:process_running) do |c|
        c.running = true
        c.interval = 5.seconds
        # c.notify = 'engineering'
      end

      # failsafe
      on.condition(:tries) do |c|
        c.times = 5
        c.transition = :start
        c.interval = 5.seconds
        # c.notify = 'engineering'
      end
    end

    # start if process is not running
    w.transition(:up, :start) do |on|
      on.condition(:process_running) do |c|
        c.running = false
        c.notify = {:contacts => ['engineering'], :priority => 1, :category => "workers"}
      end
    end


  end
end

请告诉我您的想法。

最佳答案

看来我找到了问题的根源。在我的路线文件中,我添加了对方法的调用以加载一些动态路线,看起来 resque 不喜欢它,只是一直杀死进程而不说任何事情(仍然很奇怪)。然而,在删除该行 (DynamicRouter.load) 后,工作人员停止了这种疯狂的行为。我希望这对其他人有帮助,我很乐意提供更多关于我能找到的内容的详细信息。

关于ruby-on-rails - Resque worker 默默地死去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46043701/

相关文章:

java - 在 Java 中设计确认 token

ruby-on-rails - 从集合 ActiveRecord 对象中获取特定列?

ruby-on-rails - 带图片 uploader 的多步表单

ruby-on-rails - 使用第 3 方库通过 http 发送电子邮件时可以使用 ActionMailer 吗?

ruby-on-rails - 设计 - 设置邮件程序

lua - 在Redis中编写Lua脚本时如何包含第三方库

ruby-on-rails - 功能测试和嵌套资源

ruby - 使用 Passenger 部署多个 Rail 3.1 应用程序的 'official' 方法

node.js - Redis - 一台机器上的 Node.js?

clojure - 胭脂红中的奇怪行为(clojure-redis 客户端)