Method: Sentry::BackgroundWorker#initialize

Defined in:
lib/sentry/background_worker.rb

#initialize(configuration) ⇒ BackgroundWorker



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sentry/background_worker.rb', line 17

def initialize(configuration)
  @shutdown_timeout = 1
  @number_of_threads = configuration.background_worker_threads
  @max_queue = configuration.background_worker_max_queue
  @sdk_logger = configuration.sdk_logger
  @debug = configuration.debug
  @shutdown_callback = nil

  @executor =
    if @number_of_threads == 0
      log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously")
      Concurrent::ImmediateExecutor.new
    else
      log_debug("Initializing the Sentry background worker with #{@number_of_threads} threads")

      executor = Concurrent::ThreadPoolExecutor.new(
        min_threads: 0,
        max_threads: @number_of_threads,
        max_queue: @max_queue,
        fallback_policy: :discard
      )

      @shutdown_callback = proc do
        executor.shutdown
        executor.wait_for_termination(@shutdown_timeout)
      end

      executor
    end
end