Sha256: 72f011ac298332764d2b2881b2ea23e5b0d323f490f96b731e2ee71961f08fac

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

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

require 'contrast/agent/worker_thread'
require 'contrast/agent/reporting/report'

module Contrast
  module Agent
    # The ServiceHeartbeat functions to keep the Contrast Service alive and ensure that it maintains this Agent's
    # ApplicationContext.
    class ServiceHeartbeat < WorkerThread
      # Spec recommends 30 seconds, we're going with 15.
      REFRESH_INTERVAL_SEC = 15

      def start_thread!
        return if ::Contrast::CONTRAST_SERVICE.unnecessary?
        return if running?

        @_thread = Contrast::Agent::Thread.new do
          logger.info('Starting heartbeat thread.')
          loop do
            logger.info("Queue Size: #{ Contrast::Agent.messaging_queue.queue&.length }")
            Contrast::Agent.messaging_queue&.send_event_eventually(poll_message)
            clean_properties
            sleep(REFRESH_INTERVAL_SEC)
          end
        end
      end

      def poll_message
        @_poll_message ||= Contrast::Api::Dtm::Poll.new
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-6.6.4 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.6.3 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.6.2 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.6.1 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.6.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.5.1 lib/contrast/agent/service_heartbeat.rb
contrast-agent-6.5.0 lib/contrast/agent/service_heartbeat.rb