【问题标题】:Debug a daemon in RubyMine在 RubyMine 中调试守护进程
【发布时间】:2014-07-15 22:45:06
【问题描述】:

有没有办法在 Ruby Mine 中调试守护进程。我调用这个文件的方式是这样的

Daemons.run(文件,选项)

file 是文件名,options 是我传递给文件的一堆选项。

【问题讨论】:

  • 您使用的是哪个版本的 ruby​​mine...?

标签: ruby debugging daemon


【解决方案1】:

我也在尝试调试 Rails 守护进程(gem 守护进程)。特别是 ActiveMessaging 轮询脚本。但是由于各种原因(竞争条件等),ruby-debug-ide 无法附加。

我想出的解决方案是使用 gem rails-daemons。这适用于 ActiveMessaging,允许我创建各种守护进程,重要的是,能够在 RubyMine 中调试它们

解决方法

使用https://github.com/mirasrael/daemons-rails 创建一个新的守护进程。这适用于 OSX 10.8.x 上的 RubyMine 6.3.3、Rails 4、Ruby 2.1.2

示例守护进程

mqpoller.rb(运行rails后生成守护进程mqpoller)

#!/usr/bin/env ruby

# You might want to change this
ENV["RAILS_ENV"] ||= "development"

root = File.expand_path(File.dirname(__FILE__))
root = File.dirname(root) until File.exists?(File.join(root, 'config'))
Dir.chdir(root)

require File.join(root, "config", "environment")

$running = true
Signal.trap("TERM") do 
  $running = false
end

while($running) do

    # Replace this with your code
    Rails.logger.auto_flushing = true
    Rails.logger.info "This daemon is still running at #{Time.now}.\n"

    # ADDED MY CODE BELOW HERE TO START ActiveMessaging

    Rails.logger = Logger.new(STDOUT)
    ActiveMessaging.logger = Rails.logger

    # Load ActiveMessaging
    ActiveMessaging::load_processors

    # Start it up!
    ActiveMessaging::start

    sleep 10
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 2013-04-16
    相关资源
    最近更新 更多