Class: Sentry::BackgroundWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/background_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ BackgroundWorker



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sentry/background_worker.rb', line 9

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_queueObject (readonly)

Returns the value of attribute max_queue.



7
8
9
# File 'lib/sentry/background_worker.rb', line 7

def max_queue
  @max_queue
end

#number_of_threadsObject (readonly)

Returns the value of attribute number_of_threads.



7
8
9
# File 'lib/sentry/background_worker.rb', line 7

def number_of_threads
  @number_of_threads
end

Instance Method Details

#perform(&block) ⇒ Object



32
33
34
35
36
# File 'lib/sentry/background_worker.rb', line 32

def perform(&block)
  @executor.post do
    block.call
  end
end