Class: EvilEvents::Core::Events::Notifier::Worker::Executor Private
- Inherits:
-
Object
- Object
- EvilEvents::Core::Events::Notifier::Worker::Executor
- Includes:
- Logging
- Defined in:
- lib/evil_events/core/events/notifier/worker/executor.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
since 0.3.0
Constant Summary collapse
- FALLBACK_POLICIES =
{ exception: :abort, ignorance: :discard, main_thread: :caller_runs }.freeze
Instance Attribute Summary collapse
- #options ⇒ Hash readonly private
- #raw_executor ⇒ Concurrent::ThreadPoolExecutor readonly private
Instance Method Summary collapse
-
#execute(job) ⇒ Concurrent::Promise
private
rubocop:disable Metrics/AbcSize, Style/MultilineBlockChain.
-
#initialize(min_threads:, max_threads:, max_queue:, fallback_policy:) ⇒ Executor
constructor
private
A new instance of Executor.
- #initialize_raw_executor!(**options) ⇒ Concurrent::ThreadPoolExecutor private private
-
#restart! ⇒ Object
private
Void.
-
#shutdown! ⇒ Object
private
Void.
Methods included from Logging
#log_activity, #log_failure, #log_success
Constructor Details
#initialize(min_threads:, max_threads:, max_queue:, fallback_policy:) ⇒ Executor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Executor.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 37 def initialize(min_threads:, max_threads:, max_queue:, fallback_policy:) raise EvilEvents::IncorrectFallbackPolicyError unless FALLBACK_POLICIES[fallback_policy] = { min_threads: min_threads, max_threads: max_threads, max_queue: max_queue, fallback_policy: FALLBACK_POLICIES[fallback_policy] }.freeze initialize_raw_executor!(**) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 27 def end |
#raw_executor ⇒ Concurrent::ThreadPoolExecutor (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 21 def raw_executor @raw_executor end |
Instance Method Details
#execute(job) ⇒ Concurrent::Promise
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/AbcSize, Style/MultilineBlockChain
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 57 def execute(job) Concurrent::Promise.new(executor: raw_executor) do job.perform end.on_success do log_success(job.event, job.subscriber) end.on_error do |error| log_failure(job.event, job.subscriber) job.event.__call_on_error_hooks__(error) end.execute rescue Concurrent::RejectedExecutionError raise EvilEvents::WorkerDisabledOrBusyError end |
#initialize_raw_executor!(**options) ⇒ Concurrent::ThreadPoolExecutor (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 99 def initialize_raw_executor!(**) @raw_executor = Concurrent::ThreadPoolExecutor.new(**) end |
#restart! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
84 85 86 87 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 84 def restart! shutdown! initialize_raw_executor!(**) end |
#shutdown! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
75 76 77 78 |
# File 'lib/evil_events/core/events/notifier/worker/executor.rb', line 75 def shutdown! raw_executor.shutdown raw_executor.wait_for_termination end |