سؤال

لقد كتبت نص قارئ Ruby NFC وقمت بالخليط مع Gemons Gem. كل شيء يعمل بشكل رائع باستثناء البرنامج النصي الذي يعمل مرة واحدة فقط ...

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