Sha256: 193e08874091f2bdddb965e1dac71c1ac97e333fedc1396fd40b1733b9ffaa76

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

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

cs__scoped_require 'contrast/components/interface'

module Contrast
  module Agent
    # The ServiceHeartbeat functions to keep the Contrast Service alive and
    # ensure that it maintains this Agent's ApplicationContext.
    class ServiceHeartbeat
      include Contrast::Components::Interface
      access_component :contrast_service, :logging

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

      def updater_thread
        @_updater_thread ||= Contrast::Agent::Thread.new do
          logger.debug(nil, 'Starting heartbeat thread.')
          loop do
            begin
              logger.debug(nil, 'Sending Heartbeat...')
              # TODO: RUBY-672: Change noop to poll messages
              CONTRAST_SERVICE.queue_message(Contrast::Api::Dtm::Noop.new)
            end
            sleep REFRESH_INTERVAL_SEC
          end
        end
      end
      alias_method :start, :updater_thread

      def stop
        Thread.kill(@_updater_thread) if @_updater_thread&.alive?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-3.8.5 lib/contrast/agent/service_heartbeat.rb
contrast-agent-3.8.4 lib/contrast/agent/service_heartbeat.rb