Sha256: 8048ec5b2f5731796fd2d8729f841b0acd22074b90788759e08dde665c4f1392

Contents?: true

Size: 1.19 KB

Versions: 53

Compression:

Stored size: 1.19 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 = {
  :app_name => 'mytask',
#  :ontop => true,
  :multiple => true
}


Daemons.call(options) do
  File.open(testfile, 'w') {|f|
    f.puts "test"
  }

  loop { puts "1"; sleep 5 }
end
puts "first task started"

Daemons.call do
  loop { puts "2"; sleep 4 }
end
puts "second task started"

# NOTE: this process will exit after 5 seconds
Daemons.call do
  puts "3"
  sleep 5
end
puts "third task started"

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

# 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

53 entries across 53 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.7.4 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.7.3 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/daemons-1.1.9/examples/call/call.rb
blue-daemons-1.1.11 examples/call/call.rb
mlanett-daemons-1.1.10.3 examples/call/call.rb
mlanett-daemons-1.1.10.2 examples/call/call.rb
classiccms-0.7.2 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.7.1 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.7.0 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.9 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.8 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.7 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.6 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.5 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.4 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.3 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.2 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.1 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb
classiccms-0.6.0 vendor/bundle/gems/daemons-1.1.8/examples/call/call.rb