Sha256: f64af50d4a3175c6effb18e7b4267dcb6d8e1fd98a13f7a011291255df13780f

Contents?: true

Size: 879 Bytes

Versions: 9

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module DatadogBackup
  module ThreadPool
    TPOOL = ::Concurrent::ThreadPoolExecutor.new(
      min_threads: [2, Concurrent.processor_count].max,
      max_threads: [2, Concurrent.processor_count].max * 2,
      fallback_policy: :abort
    )

    def self.watcher(logger)
      Thread.new(TPOOL) do |pool|
        while pool.queue_length.positive?
          sleep 2
          logger.info("#{pool.queue_length} tasks remaining for execution.")
        end
      end
    end

    def self.shutdown(logger)
      logger.fatal 'Shutdown signal caught. Performing orderly shut down of thread pool. Press Ctrl+C again to forcibly shut down, but be warned, DATA LOSS MAY OCCUR.'
      TPOOL.shutdown
      TPOOL.wait_for_termination
    rescue SystemExit, Interrupt
      logger.fatal 'OK Nuking, DATA LOSS MAY OCCUR.'
      TPOOL.kill
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
datadog_backup-2.0.1 lib/datadog_backup/thread_pool.rb
datadog_backup-2.0.0 lib/datadog_backup/thread_pool.rb
datadog_backup-1.1.4 lib/datadog_backup/thread_pool.rb
datadog_backup-1.1.3 lib/datadog_backup/thread_pool.rb
datadog_backup-1.1.2 lib/datadog_backup/thread_pool.rb
datadog_backup-1.1.1 lib/datadog_backup/thread_pool.rb
datadog_backup-1.1.0 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.5 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.4 lib/datadog_backup/thread_pool.rb