Sha256: 759fe6076448829ccc4c47ce2f7b983900f0316bf68db73d11e525b7fec33e7a

Contents?: true

Size: 1.84 KB

Versions: 38

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

module OneApm
  module Agent
    class Agent
      module ForkableDispatcherFunctions

        def after_fork(options={})
          needs_restart = false
          @after_fork_lock.synchronize do
            needs_restart = @harvester.needs_restart?
            @harvester.mark_started
          end

          return if !needs_restart ||
            !Manager.config[:agent_enabled] ||
            !Manager.config[:monitor_mode] ||
            disconnected?

          OneApm::Manager.logger.debug "Starting the worker thread in #{Process.pid} (parent #{Process.ppid}) after forking."

          channel_id = options[:report_to_channel]
          install_pipe_service(channel_id) if channel_id

          reset_objects_with_locks
          drop_buffered_data

          setup_and_start_agent(options)
        end

        def install_pipe_service(channel_id)
          @service = OneApm::Collector::ForkedProcessService.new(channel_id)
          if connected?
            @connected_pid = Process.pid
          else
            OneApm::Manager.logger.debug("Child process #{Process.pid} not reporting to non-connected parent (process #{Process.ppid}).")
            @service.shutdown(Time.now)
            disconnect
          end
        end

        def synchronize_with_harvest
          harvest_lock.synchronize do
            yield
          end
        end

        def reset_objects_with_locks
          @stats_engine = OneApm::Collector::StatsEngine.new
          reset_harvest_locks
        end

        def reset_harvest_locks
          return if harvest_lock.nil?

          harvest_lock.unlock if harvest_lock.locked?
        end

        def flush_pipe_data
          if connected? && @service.is_a?(::OneApm::Collector::ForkedProcessService)
            transmit_data
            transmit_event_data
          end
        end

      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.4.1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.4.0 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.7 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.6 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.5 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.4 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.3 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.2 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.0 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb
oneapm_rpm-1.2.9 lib/one_apm/agent/agent/forkable_dispatcher_functions.rb