Class: Sentry::BackgroundWorker
- Defined in:
- lib/sentry/background_worker.rb
Instance Attribute Summary collapse
-
#max_queue ⇒ Object
readonly
Returns the value of attribute max_queue.
-
#number_of_threads ⇒ Object
readonly
Returns the value of attribute number_of_threads.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ BackgroundWorker
constructor
A new instance of BackgroundWorker.
- #perform(&block) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ BackgroundWorker
Returns a new instance of BackgroundWorker.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sentry/background_worker.rb', line 8 def initialize(configuration) @max_queue = 30 @number_of_threads = configuration.background_worker_threads @executor = if configuration.async configuration.logger.debug(LOGGER_PROGNAME) { "config.async is set, BackgroundWorker is disabled" } Concurrent::ImmediateExecutor.new elsif @number_of_threads == 0 configuration.logger.debug(LOGGER_PROGNAME) { "config.background_worker_threads is set to 0, all events will be sent synchronously" } Concurrent::ImmediateExecutor.new else configuration.logger.debug(LOGGER_PROGNAME) { "initialized a background worker with #{@number_of_threads} threads" } Concurrent::ThreadPoolExecutor.new( min_threads: 0, max_threads: @number_of_threads, max_queue: @max_queue, fallback_policy: :discard ) end end |
Instance Attribute Details
#max_queue ⇒ Object (readonly)
Returns the value of attribute max_queue.
6 7 8 |
# File 'lib/sentry/background_worker.rb', line 6 def max_queue @max_queue end |
#number_of_threads ⇒ Object (readonly)
Returns the value of attribute number_of_threads.
6 7 8 |
# File 'lib/sentry/background_worker.rb', line 6 def number_of_threads @number_of_threads end |
Instance Method Details
#perform(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/sentry/background_worker.rb', line 31 def perform(&block) @executor.post do block.call end end |