我已经写了红宝石NFC阅读器的脚本,并与守护宝石daemonised它。这一切的伟大工程,除了脚本只运行一次......

Daemon.rb

require 'rubygems'
require 'daemons'

pwd  = File.dirname(File.expand_path(__FILE__))
file = pwd + '/touchatag.rb'

Daemons.run_proc(
  'touchatag_project_daemon', # name of daemon
  :dir_mode => :normal,
  :dir => File.join(pwd, 'tmp/pids'), # directory where pid file will be stored
  :backtrace => true,
  :monitor => true,
  :log_output => true
) do
  exec "ruby #{file}"
end

touchatag.rb

quire 'rubygems'
require 'nfc'
require 'httparty'

class TagAssociator
  include HTTParty
  base_uri 'localhost:3000'
end

NFC.instance.find do |tag|
  puts "Processing tag..."
  TagAssociator.post('/answers/answer', :query => {:uid => tag.uid})
end

这伟大工程,我收到我的应用程序的tag.uid。但是,当我扫描另一个RFID标签的脚本不会再次运行...

有谁知道如何调整脚本运行“永远”,当守护程序停止停止?

由于

更新

我更新我的脚本daemon.rb:

require 'rubygems'
require 'daemons'

options = {
  :app_name   => "touchatag_project_daemon",
  :ARGV       => ['start', '-f', '--', 'param_for_myscript'],
  :dir_mode   => :script,
  :dir        => 'tmp/pids',
  :multiple   => true,
  :ontop      => true,
  # :mode       => :exec,
  :backtrace  => true,
  :monitor    => true
}

Daemons.run(File.join(File.dirname(__FILE__), '/touchatag.rb'), options)

但它只是运行一次......我不明白,任何其他建议?

有帮助吗?

解决方案

您几乎可以肯定要使用Daemon.run。如果你想将代码从run_proc进入touchtag.rb Daemon.rb将是有益的。

http://daemons.rubyforge.org/classes/Daemons.html#M000004

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top