Class: StalkBoss::Stalk

Inherits:
Object
  • Object
show all
Defined in:
lib/stalk_boss.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, workers = 1, log = nil, error_log = nil) ⇒ Stalk

Returns a new instance of Stalk.



39
40
41
42
43
44
45
# File 'lib/stalk_boss.rb', line 39

def initialize(worker, workers=1, log=nil, error_log=nil)
  super
  @worker    = worker
  @workers   = workers
  @log       = log
  @error_log = error_log
end

Instance Attribute Details

#error_logObject

Returns the value of attribute error_log.



37
38
39
# File 'lib/stalk_boss.rb', line 37

def error_log
  @error_log
end

#logObject

Returns the value of attribute log.



37
38
39
# File 'lib/stalk_boss.rb', line 37

def log
  @log
end

#workerObject

Returns the value of attribute worker.



37
38
39
# File 'lib/stalk_boss.rb', line 37

def worker
  @worker
end

#workersObject

Returns the value of attribute workers.



37
38
39
# File 'lib/stalk_boss.rb', line 37

def workers
  @workers
end

Instance Method Details

#pidsObject



47
48
49
# File 'lib/stalk_boss.rb', line 47

def pids
  @pids ||= []
end

#startObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/stalk_boss.rb', line 51

def start
  (1..@workers).each do
    pids << fork do
      STDOUT.reopen(File.open(@log, 'a')) if @log
      STDERR.reopen(File.open(@error_log, 'a')) if @error_log
      STDERR.sync = STDOUT.sync = true
      exec 'bossed_stalk', @worker
    end
  end
end