Sha256: 3bdca1ac87107a3e0c6bb940694e9553e8ed58f7d0e82b3909925a426518483c

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

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

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

module Contrast
  module Agent
    module ReportingWorkers
      # The ApplicationServerWorker 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 ApplicationStartup is complete.
      class ApplicationServerWorker < WorkerThread
        RESEND_INTERVAL_MS = 30_000.cs__freeze

        def start_thread!
          return if running?

          @_thread = Contrast::Agent::Thread.new do
            logger.info('[ApplicationSettingsWorker] Starting thread.', sending_interval: application_server_ms)
            loop do
              logger.info('[ApplicationSettingsWorker] Fetching Settings', sending_interval: application_server_ms)
              Contrast::Agent.reporter&.send_event(application_settings_message)
              sleep(application_server_ms / 1000)
            end
          end
        end

        private

        # This method will generate the reporting event for the application settings
        #
        # @return [Contrast::Agent::Reporting::ReportingEvent]
        def application_settings_message
          @_application_settings_message ||= Contrast::Agent::Reporting::ApplicationSettings.new
        end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-7.0.0 lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb
contrast-agent-6.15.3 lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb
contrast-agent-6.15.2 lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb
contrast-agent-6.15.1 lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb
contrast-agent-6.15.0 lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb