Sha256: bfaec65f56a146d74b8631f62bd7229b327aaf35928c31fec7bf3097a5ad5775

Contents?: true

Size: 1.27 KB

Versions: 17

Compression:

Stored size: 1.27 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 :app_context, :logging

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

        private

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

          logger.trace('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 = APP_CONTEXT.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.trace('Detected startup within Rake task')
          true
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.4.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.3.2 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.3.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.3.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.2.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.1.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-4.0.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.16.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.15.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.14.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.13.2 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.13.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.13.0 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.12.2 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.12.1 lib/contrast/utils/job_servers_running.rb
contrast-agent-3.12.0 lib/contrast/utils/job_servers_running.rb