Sha256: ce8f98267335a7f70b69f30c0a2625b4e974c98d7634e072af06ed30cdb7c139

Contents?: true

Size: 1.15 KB

Versions: 114

Compression:

Stored size: 1.15 KB

Contents

lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))

if File.exist?(File.join(lib_dir, 'daemons.rb'))
  $LOAD_PATH.unshift lib_dir
else
  begin; require 'rubygems'; rescue ::Exception; end
end


require 'daemons'

testfile = File.expand_path(__FILE__) + '.log'


# On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
# will be created an the options will be kept within, so you only have to specify
# <tt>:multiple</tt> once.
#

options = {
#  :ontop => true,
  :multiple => true,
  :monitor => true
}


Daemons.call(options) do
  loop { puts "1"; sleep 20 }
end
puts "first task started"


# NOTE: this process will exit after 5 seconds
Daemons.call do
  File.open(testfile, 'a') {|f|
    f.puts "started..."
    puts "2"
  
    sleep 5

    f.puts "...exit"
  }
end
puts "second task started"

puts "waiting 100 seconds..."
sleep(100)

# This call would result in an exception as it will try to kill the third process 
# which has already terminated by that time; but using the 'true' parameter forces the
# stop_all procedure.
puts "trying to stop all tasks..."
Daemons.group.stop_all(true)

puts "done"

Version data entries

114 entries across 114 versions & 13 rubygems

Version Path
classiccms-0.5.17 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.16 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.15 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.14 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.13 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.12 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.11 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.10 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.9 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.8 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
daemons-1.1.9 examples/call/call_monitor.rb
classiccms-0.5.7 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.6 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.5 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.2 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.1 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.5.0 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.4.2 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.4.1 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb
classiccms-0.4.0 vendor/bundle/gems/daemons-1.1.8/examples/call/call_monitor.rb