Sha256: 64f8415449471c5595a1576a782ebd3e8f64a0ed260a657fadc96c038f7cbb54

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

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

module Contrast
  module Utils
    # A module that detects whether any job servers attached to
    # the application are running
    module JobServersRunning
      include Contrast::Components::Interface
      access_component :logging

      class << self
        def job_servers_running?
          sidekiq_running? || rake_running?
        end

        def sidekiq_running?
          return unless defined?(Sidekiq) && Sidekiq.cs__respond_to?(:server?) && Sidekiq.server?

          logger.debug(nil, 'Detected the spawn of a Sidekiq process')
          true
        end

        def rake_running?
          return unless defined?(Rake) &&
              Rake.cs__respond_to?(:application) &&
              Rake.application.cs__respond_to?(:top_level_tasks)

          disabled_rake_tasks = Contrast::Agent::FeatureState.instance.disabled_agent_rake_tasks
          has_disabled_task = Rake.application.top_level_tasks.any? { |top_level_task| disabled_rake_tasks.include?(top_level_task) }
          return false unless has_disabled_task

          logger.debug(nil, 'Detected startup within Rake task')
          true
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.10.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.10.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.9.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.9.0 lib/contrast/utils/job_servers_running.rb