Class: Gorgon::WorkerManager

Inherits:
Object
  • Object
show all
Includes:
CrashReporter, GLogger, PipeForker
Defined in:
lib/gorgon/worker_manager.rb

Constant Summary collapse

STDOUT_FILE =
'/tmp/gorgon-worker-mgr.out'
STDERR_FILE =
'/tmp/gorgon-worker-mgr.err'

Constants included from CrashReporter

CrashReporter::OUTPUT_LINES_TO_REPORT

Constants included from GLogger

GLogger::SIZE_1_MB

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CrashReporter

#report_crash, #send_crash_message

Methods included from GLogger

#initialize_logger, #log, #log_error

Methods included from PipeForker

#pipe_fork

Constructor Details

#initialize(config) ⇒ WorkerManager

Returns a new instance of WorkerManager.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gorgon/worker_manager.rb', line 36

def initialize config
  initialize_logger config[:log_file]
  log "Worker Manager #{Gorgon::VERSION} initializing"

  @worker_pids = []

  @config = config

  payload = Yajl::Parser.new(:symbolize_keys => true).parse($stdin.read)
  @job_definition = JobDefinition.new(payload)

  @callback_handler = Gorgon::CallbackHandler.new(@job_definition.callbacks)
  @available_worker_slots = config[:worker_slots]

  connect
end

Class Method Details

.build(listener_config_file) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/gorgon/worker_manager.rb', line 19

def self.build listener_config_file
  @listener_config_file = listener_config_file
  config = Configuration.load_configuration_from_file(listener_config_file)

  redirect_output_to_files

  new config
end

.redirect_output_to_filesObject



28
29
30
31
32
33
34
# File 'lib/gorgon/worker_manager.rb', line 28

def self.redirect_output_to_files
  STDOUT.reopen(File.open(STDOUT_FILE, 'w'))
  STDOUT.sync = true

  STDERR.reopen(File.open(STDERR_FILE, 'w'))
  STDERR.sync = true
end

Instance Method Details

#manageObject



53
54
55
# File 'lib/gorgon/worker_manager.rb', line 53

def manage
  fork_workers @available_worker_slots
end