Sha256: ab1668a1968e5c1186b23a9070841f937cda38136c2d3d082914b9b5a3aef5dc

Contents?: true

Size: 939 Bytes

Versions: 10

Compression:

Stored size: 939 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,
      max_queue: [2, Concurrent.processor_count].max * 512,
      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

10 entries across 10 versions & 1 rubygems

Version Path
datadog_backup-1.0.3 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.2 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.1 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.1.alpha.1 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.0 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.0.alpha.2 lib/datadog_backup/thread_pool.rb
datadog_backup-1.0.0.alpha.1 lib/datadog_backup/thread_pool.rb
datadog_backup-0.11.0 lib/datadog_backup/thread_pool.rb
datadog_backup-0.10.3 lib/datadog_backup/thread_pool.rb
datadog_backup-0.11.0.alpha.1 lib/datadog_backup/thread_pool.rb