Sha256: 0dcdcc2241e214ea8eaa6e47a275bb4b55a1c8956f433645abde6644cc3dcae8

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'

module Contrast
  module Agent
    # Base class for threads that do async processing
    class WorkerThread
      include Contrast::Components::Logger::InstanceMethods

      def initialize
        @_thread = nil
      end

      def running?
        !!@_thread&.alive?
      end

      def stop!
        return unless running?
        return unless @_thread

        Thread.kill(@_thread)
        @_thread = nil
      end

      # Most threads, we always want to start. Some may be controlled by feature guards though, so we need to check.
      #
      # @return [Boolean]
      def attempt_to_start?
        Contrast::AGENT.enabled?
      end

      def clean_properties
        logger.debug("Cleaning PROPERTIES_HASH size: #{ Contrast::Agent::Assess::Tracker::PROPERTIES_HASH.size }")
        Contrast::Agent::Assess::Tracker.cleanup!
        logger.debug("Cleaned PROPERTIES_HASH size: #{ Contrast::Agent::Assess::Tracker::PROPERTIES_HASH.size }")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.6.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.5.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.4.1 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.4.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.3.2 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.3.1 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.3.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.2.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.1.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-7.0.0 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-6.15.3 lib/contrast/agent/thread/worker_thread.rb
contrast-agent-6.15.2 lib/contrast/agent/thread/worker_thread.rb