Sha256: 1d2c9339b402968d8def30e746aa8d7e847584555d1c62276fad57f6c8e3d892

Contents?: true

Size: 1.19 KB

Versions: 15

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') do |f|
    f.puts 'test'
  end

  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

15 entries across 13 versions & 4 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/daemons-1.4.1/examples/call/call.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/daemons-1.4.1/examples/call/call.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/daemons-1.4.1/examples/call/call.rb
daemons-1.4.1 examples/call/call.rb
daemons-1.4.0 examples/call/call.rb
daemons-1.3.1 examples/call/call.rb
daemons-1.3.0 examples/call/call.rb
daemons-1.2.6 examples/call/call.rb
daemons-1.2.5 examples/call/call.rb
arcabouco-0.2.13 vendor/bundle/gems/daemons-1.2.4/examples/call/call.rb
daemons-1.2.4 examples/call/call.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/daemons-1.2.3/examples/call/call.rb
daemons-1.2.3 examples/call/call.rb
daemons-1.2.2 examples/call/call.rb
daemons-1.2.1 examples/call/call.rb