Class: Salemove::ProcessHandler::PivotProcess

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

Defined Under Namespace

Classes: Benchmarker, ServiceSpawner, TapServiceSpawner

Constant Summary collapse

DEFAULT_FULFILLABLE_TIMEOUT =
3
DEFAULT_EXECUTION_TIME_KEY =
'service.execution_time'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(freddy:, logger:, statsd:, notifier: nil, notifier_factory: NotifierFactory, process_monitor: ProcessMonitor.new, process_name: 'Unknown process', log_error_as_string: false, execution_time_key: DEFAULT_EXECUTION_TIME_KEY, exit_enforcer: nil) ⇒ PivotProcess

Returns a new instance of PivotProcess.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/salemove/process_handler/pivot_process.rb', line 15

def initialize(freddy:,
               logger:,
               statsd:,
               notifier: nil,
               notifier_factory: NotifierFactory,
               process_monitor: ProcessMonitor.new,
               process_name: 'Unknown process',
               log_error_as_string: false,
               execution_time_key: DEFAULT_EXECUTION_TIME_KEY,
               exit_enforcer: nil)
  @freddy = freddy
  @logger = logger
  @benchmarker = Benchmarker.new(
    statsd: statsd,
    application: process_name,
    execution_time_key: execution_time_key
  )
  @process_monitor = process_monitor
  @exception_notifier = notifier_factory.get_notifier(process_name, notifier)
  # Needed for forcing exit from jruby with exit(0)
  @exit_enforcer = exit_enforcer || Proc.new {}
  @log_error_as_string = log_error_as_string
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

Instance Method Details

#spawn(service, blocking: true) ⇒ Object



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

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/salemove/process_handler/pivot_process.rb', line 46

def spawn_queue_threads(service)
  if service.class.const_defined?(:QUEUE)
    [
      ServiceSpawner.new(
        service,
        freddy: @freddy,
        logger: @logger,
        benchmarker: @benchmarker,
        exception_notifier: @exception_notifier,
        log_error_as_string: @log_error_as_string
      ).spawn
    ]
  else
    []
  end
end

#spawn_tap_threads(service) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/salemove/process_handler/pivot_process.rb', line 63

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