# encoding: utf-8 module OneApm module Agent class Harvester attr_accessor :starting_pid def initialize(events, after_forker = OneApm::Manager) @starting_pid = nil @after_forker = after_forker if events events.subscribe(:start_transaction, &method(:on_transaction)) end end def on_transaction(*_) return unless restart_in_children_enabled? && needs_restart? && harvest_thread_enabled? restart_harvest_thread end def mark_started(pid = Process.pid) @starting_pid = pid end def needs_restart?(pid = Process.pid) @starting_pid != pid end def restart_in_children_enabled? OneApm::Manager.config[:restart_thread_in_children] end def harvest_thread_enabled? !OneApm::Manager.config[:disable_harvest_thread] end def restart_harvest_thread @after_forker.after_fork(:force_reconnect => true) end end end end