0

我编写了一个 ruby​​ NFC 阅读器脚本,并使用 daemons gem 对其进行了守护。一切都很好,除了脚本只运行一次......

守护进程.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

触摸标签.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)

但它只运行一次......我没有任何其他建议?

4

1 回答 1

1

你几乎肯定想要使用Daemon.run. run_proc如果您想将代码touchtag.rbDaemon.rb.

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

于 2011-01-05T16:56:50.990 回答