Sha256: 317b6bb1cba8ba9a5765966286943938f31dfba47b7134b862a21fcc33eff05d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 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 ServerSettingsWorker will send request on interval, to make sure the Agent gets the settings it
    # need to operate, from TS. This Thead should be started after the AgentStartup is complete.
    class ServerSettingsWorker < WorkerThread
      RESEND_INTERVAL_MS = 60_000.cs__freeze

      def start_thread!
        return if running?

        @_thread = Contrast::Agent::Thread.new do
          logger.info('Starting Server Settings Worker thread.', sending_interval: server_settings_resend_ms)
          loop do
            logger.info('Fetching Settings', sending_interval: server_settings_resend_ms)
            Contrast::Agent.reporter&.send_event(settings_message)
            sleep(server_settings_resend_ms / 1000)
          end
        end
      end

      private

      # Polling messages for this thread. Including Server settings:
      #
      # @return [Contrast::Agent::Reporting::ReportingEvent]
      def settings_message
        @_settings_message ||= Contrast::Agent::Reporting::ServerSettings.new
      end

      # Get the value from settings or use the default one.
      #
      # @return resend_ms [Integer] time to resend the message
      def server_settings_resend_ms
        @_server_settings_resend_ms ||= Contrast::AGENT.polling.server_settings_ms&.to_i || RESEND_INTERVAL_MS
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-6.9.0 lib/contrast/agent/reporting/server_settings_worker.rb