Class: Salemove::ProcessHandler::PivotProcess
- Inherits:
-
Object
- Object
- Salemove::ProcessHandler::PivotProcess
- 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
-
#exception_notifier ⇒ Object
readonly
Returns the value of attribute exception_notifier.
-
#process_monitor ⇒ Object
readonly
Returns the value of attribute process_monitor.
Instance Method Summary collapse
-
#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
constructor
A new instance of PivotProcess.
- #spawn(service, blocking: true) ⇒ Object
- #spawn_queue_threads(service) ⇒ Object
- #spawn_tap_threads(service) ⇒ Object
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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 16 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_notifier ⇒ Object (readonly)
Returns the value of attribute exception_notifier.
14 15 16 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 14 def exception_notifier @exception_notifier end |
#process_monitor ⇒ Object (readonly)
Returns the value of attribute process_monitor.
14 15 16 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 14 def process_monitor @process_monitor end |
Instance Method Details
#spawn(service, blocking: true) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 40 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 47 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/salemove/process_handler/pivot_process.rb', line 64 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 |