Class: Salemove::ProcessHandler::PivotProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/salemove/process_handler/pivot_process.rb

Defined Under Namespace

Classes: ServiceSpawner, TapServiceSpawner

Constant Summary collapse

DEFAULT_FULFILLABLE_TIMEOUT =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messenger, env: 'development', notifier: nil, notifier_factory: NotifierFactory, process_monitor: ProcessMonitor.new, process_name: 'Unknown process', exit_enforcer: nil) ⇒ PivotProcess

Returns a new instance of PivotProcess.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/salemove/process_handler/pivot_process.rb', line 23

def initialize(messenger,
               env: 'development',
               notifier: nil,
               notifier_factory: NotifierFactory,
               process_monitor: ProcessMonitor.new,
               process_name: 'Unknown process',
               exit_enforcer: nil)
  @messenger = messenger
  @process_monitor = process_monitor
  @exception_notifier = notifier_factory.get_notifier(env, process_name, notifier)
  # Needed for forcing exit from jruby with exit(0)
  @exit_enforcer = exit_enforcer || Proc.new {}
end

Instance Attribute Details

#exception_notifierObject (readonly)

Returns the value of attribute exception_notifier.



13
14
15
# File 'lib/salemove/process_handler/pivot_process.rb', line 13

def exception_notifier
  @exception_notifier
end

#process_monitorObject (readonly)

Returns the value of attribute process_monitor.



13
14
15
# File 'lib/salemove/process_handler/pivot_process.rb', line 13

def process_monitor
  @process_monitor
end

Class Method Details

.loggerObject



15
16
17
# File 'lib/salemove/process_handler/pivot_process.rb', line 15

def self.logger
  @logger ||= Logger.new(STDOUT).tap { |l| l.level = Logger::INFO }
end

.logger=(logger) ⇒ Object



19
20
21
# File 'lib/salemove/process_handler/pivot_process.rb', line 19

def self.logger=(logger)
  @logger = logger
end

Instance Method Details

#spawn(service, blocking: true) ⇒ Object



37
38
39
40
41
42
# File 'lib/salemove/process_handler/pivot_process.rb', line 37

def spawn(service, blocking: true)
  @process_monitor.start

  @service_threads = spawn_queue_threads(service).concat(spawn_tap_threads(service))
  blocking ? wait_for_monitor : Thread.new { wait_for_monitor }
end

#spawn_queue_threads(service) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/salemove/process_handler/pivot_process.rb', line 44

def spawn_queue_threads(service)
  if service.class.const_defined?(:QUEUE)
    [ServiceSpawner.spawn(service, @messenger, @exception_notifier)]
  else
    []
  end
end

#spawn_tap_threads(service) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/salemove/process_handler/pivot_process.rb', line 52

def spawn_tap_threads(service)
  if service.class.const_defined?(:TAPPED_QUEUES)
    service.class::TAPPED_QUEUES.map do |queue|
      spawner = TapServiceSpawner.new(service, @messenger, @exception_notifier)
      spawner.spawn(queue)
    end
  else
    []
  end
end