Class: Forking

Inherits:
Object
  • Object
show all
Defined in:
lib/forking.rb,
lib/version.rb

Constant Summary collapse

VERSION =
"0.1"

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Forking

opts:

:name
:sync_log
:log_file
:pid_file
:working_dir *


13
14
15
16
17
# File 'lib/forking.rb', line 13

def initialize(opts = {})
  @opts = opts
  @merge_opts = opts.update(:sync_log => nil) # sync_log should specify for each spawn
  @procs = []    
end

Instance Method Details

#after_fork(&block) ⇒ Object



32
33
34
# File 'lib/forking.rb', line 32

def after_fork(&block)
  @after_fork = block
end

#before_fork(&block) ⇒ Object



28
29
30
# File 'lib/forking.rb', line 28

def before_fork(&block)
  @before_fork = block
end

#run!Object



19
20
21
22
# File 'lib/forking.rb', line 19

def run!
  $0 = "#{@opts[:name]} spawner" unless @opts[:dont_touch_pl]
  DaemonSpawnBase.spawn!(@opts.merge(:procs => @procs, :before_fork => @before_fork, :application => @opts[:name]))
end

#spawn(opts = {}, &block) ⇒ Object



24
25
26
# File 'lib/forking.rb', line 24

def spawn(opts = {}, &block)
  @procs << MiniProcess.new(@merge_opts.merge(opts).merge(:after_fork => @after_fork), &block)
end