Resque工人默默地死去

时间:2017-09-04 20:31:55

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

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

我的问题是,无论出于何种原因,工作人员一直在死,只记录我的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

请让我知道你的想法。

1 个答案:

答案 0 :(得分:0)

看起来我已经解决了问题的根源。在我的路由文件中,我添加了一个方法的调用,以便加载一些动态路由,看起来像resque不喜欢它,并且只是在不说任何事情的情况下继续杀死进程(仍然非常奇怪)。然而,在删除该行(DynamicRouter.load)后,工作人员停止了疯狂的行为。我希望这有助于其他人,我很乐意提供更多有关我能找到的信息。