Sha256: 3f01d454f5125a094dfe3e21cd7304c728a3c470540c0db27a10463bb0976baa

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

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

require 'contrast/components/logger'
require 'contrast/agent/worker_thread'

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
      include Contrast::Components::Logger::InstanceMethods

      # Spec recommends 30 seconds, we're going with 15.
      REFRESH_INTERVAL_SEC = 15

      def start_thread!
        return if running?

        @_thread = Contrast::Agent::Thread.new do
          logger.info('Starting heartbeat thread.')
          loop do
            Contrast::Agent.messaging_queue.send_event_eventually(poll_message)

            sleep REFRESH_INTERVAL_SEC
          end
        end
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
contrast-agent-4.14.1 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.14.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.13.1 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.13.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.12.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.11.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.10.0 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.9.1 lib/contrast/agent/service_heartbeat.rb
contrast-agent-4.9.0 lib/contrast/agent/service_heartbeat.rb