Sha256: 32e3a6ba423378eab963b48082e0f14adb0e30694fa74187599b903d34884b7c

Contents?: true

Size: 1.17 KB

Versions: 20

Compression:

Stored size: 1.17 KB

Contents

require "concurrent/executor/thread_pool_executor"
require "concurrent/executor/immediate_executor"
require "concurrent/configuration"

module Sentry
  class BackgroundWorker
    include LoggingHelper

    attr_reader :max_queue, :number_of_threads, :logger

    def initialize(configuration)
      @max_queue = 30
      @number_of_threads = configuration.background_worker_threads
      @logger = configuration.logger

      @executor =
        if configuration.async
          log_debug("config.async is set, BackgroundWorker is disabled")
          Concurrent::ImmediateExecutor.new
        elsif @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("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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sentry-ruby-core-4.8.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.7.3 lib/sentry/background_worker.rb
sentry-ruby-core-4.7.2 lib/sentry/background_worker.rb
sentry-ruby-core-4.7.1 lib/sentry/background_worker.rb
sentry-ruby-core-4.7.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.5 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.4 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.3 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.2 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.1 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.6.0.pre.beta.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.5.2 lib/sentry/background_worker.rb
sentry-ruby-core-4.5.1 lib/sentry/background_worker.rb
sentry-ruby-core-4.5.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.5.0.pre.beta.1 lib/sentry/background_worker.rb
sentry-ruby-core-4.4.2 lib/sentry/background_worker.rb
sentry-ruby-core-4.4.1 lib/sentry/background_worker.rb
sentry-ruby-core-4.4.0 lib/sentry/background_worker.rb
sentry-ruby-core-4.4.0.pre.beta.0 lib/sentry/background_worker.rb