0

I have a simple controller and I want that controller to launch a daemon to do a background job (it read the sstdin data feeded by an Arduino board connected to the computer).

class DaemonController < ApplicationController
  def index
    require 'rubygems'
    require 'daemons'

    options = {
      :app_name => "collectTemperature",
      :multiple => true
    }
    readtty = Daemons.call(options) do
    loop {
      sleep 10
    }
    end
  end # def                                                                      
end # class       

It does create a process (from now it just sleeps but I will get into that once this simple code would work) but when I call the controller through the rails framework on the browser, I got a error message in the browser pointer to the line of the Daemon call (line 14).

SystemExit in DaemonController#index

daemons (1.1.9) lib/daemons/daemonize.rb:65:in `exit'
daemons (1.1.9) lib/daemons/daemonize.rb:65:in `call_as_daemon'
daemons (1.1.9) lib/daemons/application.rb:259:in `start_proc'
daemons (1.1.9) lib/daemons/application.rb:296:in `start'
daemons (1.1.9) lib/daemons.rb:252:in `call'
app/controllers/daemon_controller.rb:14:in `index'

I would greatly appreciate any help and am terribly sorry if that is a dumb question ;-)

tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

1

Daemons.call(options) begin rather than Daemons.call(options) do

000
  • 26,951
  • 10
  • 71
  • 101
  • Thanks a lot. I got a weird syntax error with the begin, as it seems to expect an end. I am confused. /Users/Pierre/ArduinoDevLab/ArduinoToWeb/app/controllers/daemon_controller.rb:14: syntax error, unexpected keyword_begin, expecting keyword_end Daemons.call(options) begin ^ – Pierre Pfister Mar 24 '13 at 00:43
  • Eh, seems like the documentation is flaky on `begin` vs `do`. – 000 Mar 24 '13 at 01:34