Class: Daemonite

Inherits:
Object
  • Object
show all
Includes:
Daemonism
Defined in:
lib/daemonite.rb

Constant Summary

Constants included from Daemonism

Daemonism::DAEMONISM_DEFAULT_OPTS

Instance Method Summary collapse

Methods included from Daemonism

#at_exit, #daemonism

Constructor Details

#initialize(opts = {}, &blk) ⇒ Daemonite

Returns a new instance of Daemonite.



156
157
158
159
# File 'lib/daemonite.rb', line 156

def initialize(opts={},&blk)
  @opts = DAEMONISM_DEFAULT_OPTS.merge(opts)
  daemonism @opts, &blk
end

Instance Method Details

#go! ⇒ Object



165
166
167
168
169
170
171
# File 'lib/daemonite.rb', line 165

def go!
  begin
    @opts[:block].call(@opts)
  rescue => e
    puts "Server stopped due to error (PID:#{Process.pid})"
  end
end

#loop! ⇒ Object



173
174
175
176
177
178
179
180
181
# File 'lib/daemonite.rb', line 173

def loop!
  begin
    loop do
      @opts[:block].call(@opts)
    end unless @opts[:block].nil?
  rescue => e
    puts "Server stopped due to error (PID:#{Process.pid})"
  end
end

#run(&block) ⇒ Object



161
162
163
# File 'lib/daemonite.rb', line 161

def run(&block)
  @opts[:block] = block
end