Sha256: 6c468dc02cc6e7ec2edcc130535135c3b9ca5f26f59889ccc29afb2457c938fd

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

module TingYun
  module Agent
    class Dispatcher
      attr_accessor :starting_pid

      def initialize(events, after_forker=TingYun::Agent)
        # We intentionally don't set our pid as started at this point.
        # Startup routines must call mark_started when they consider us set!
        @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?

        restart_harvest_thread
      end

      def restart_in_children_enabled?
        TingYun::Agent.config[:restart_thread_in_children]
      end

      def mark_started(pid = Process.pid)
        @starting_pid = pid
      end

      def needs_restart?(pid = Process.pid)
        @starting_pid != pid
      end

      def restart_harvest_thread
        @after_forker.after_fork(:force_reconnect => true)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tingyun_rpm-3.2.0 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.6.1 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.5.0 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.4.2 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.4.1 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.3.1 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.3.0 lib/ting_yun/agent/dispatcher.rb