【问题标题】:Resque workers dying silentlyResque 工人默默地死去
【发布时间】:2018-02-13 02:01:23
【问题描述】:

我在为网站设置的工作人员方面遇到问题。这是该应用程序的一些背景: 它在 rails 3.0.2 上运行,使用 mongodb、redis gem 2.2.2。为了让工作人员保持正常运行,我设置了神 gem,并指定 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

请告诉我你的想法。

【问题讨论】:

  • 您是否尝试过在任务的不同位置输出一些文本以查看它是否被执行过?另外,这仅在生产中发生吗?
  • 是的,它被执行是因为我可以看到工人不时在运行不同的作业。是的,它只发生在生产环境中。

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


【解决方案1】:

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

【讨论】:

  • 你能提供更多关于这个问题的细节吗,我在生产服务器中面临同样的问题,每当我运行一个特定的工作时,工人都会默默地死去,虽然它在生产中运行良好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-26
  • 1970-01-01
  • 2013-04-02
相关资源
最近更新 更多