Sha256: f9c88d092f93b797c8555fbab9bc636c73d8e09e5fb2bb40935c9f4d307606f2

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

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

require 'contrast/components/interface'
require 'contrast/agent/service_heartbeat'

module Contrast
  module Agent
    # This class used to ensure that our worker threads are running in multi-process environments
    class ThreadWatcher
      include Contrast::Components::Interface
      access_component :logging

      attr_reader :heartbeat

      def initialize
        @pids = {}
        @heartbeat = Contrast::Agent::ServiceHeartbeat.new
      end

      def startup!
        unless heartbeat.running?
          logger.debug('Attempting to start heartbeat thread')
          heartbeat.start_thread!
        end
        heartbeat_result = heartbeat.running?
        logger.debug('Heartbeat thread status', alive: heartbeat_result)

        unless Contrast::Agent.messaging_queue.running?
          logger.debug('Attempting to start messaging queue thread')
          Contrast::Agent.messaging_queue.start_thread!
        end
        messaging_result = Contrast::Agent.messaging_queue.running?
        logger.debug('Messaging thread status', alive: messaging_result)

        logger.debug('ThreadWatcher started threads')

        @pids[Process.pid] = messaging_result && heartbeat_result
      end

      def ensure_running?
        return if @pids[Process.pid] == true

        logger.debug('ThreadWatcher - threads not running')
        startup!
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
contrast-agent-4.3.2 lib/contrast/agent/thread_watcher.rb
contrast-agent-4.3.1 lib/contrast/agent/thread_watcher.rb
contrast-agent-4.3.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-4.2.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-4.1.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-4.0.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-3.16.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-3.15.0 lib/contrast/agent/thread_watcher.rb
contrast-agent-3.14.0 lib/contrast/agent/thread_watcher.rb