Sha256: d26114e90c2cfbc6f5a384c6d2cd1c009861ffab6b9d29c8ecc2cbc6c2c4669c

Contents?: true

Size: 918 Bytes

Versions: 13

Compression:

Stored size: 918 Bytes

Contents

module Appsignal
  class Pipe
    attr_reader :reader, :writer, :listener

    def initialize
      Appsignal.logger.debug "Initializing pipe in #{$$}"
      @reader, @writer = IO.pipe
      @listener = Thread.new do
        loop do
          Appsignal.agent.enqueue(Marshal::load(@reader))
        end
      end
      @listening = true
    end

    def write(transaction)
      Marshal::dump(transaction, @writer)
    rescue IOError
      Appsignal.logger.debug "Broken pipe in #{$$}"
      Appsignal.agent.shutdown(true, 'broken pipe')
    end

    def stop_listening!
      Thread.kill(@listener)
      @reader.close unless @reader.closed?
      @listening = false
    end

    def listening?
      !! @listening
    end

    class << self
      def init
        Thread.current[:appsignal_pipe] = Appsignal::Pipe.new
      end

      def current
        Thread.current[:appsignal_pipe]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
appsignal-0.10.6 lib/appsignal/pipe.rb
appsignal-0.10.5 lib/appsignal/pipe.rb
appsignal-0.10.4 lib/appsignal/pipe.rb
appsignal-0.10.3 lib/appsignal/pipe.rb
appsignal-0.10.2 lib/appsignal/pipe.rb
appsignal-0.10.1 lib/appsignal/pipe.rb
appsignal-0.10.0 lib/appsignal/pipe.rb
appsignal-0.9.6 lib/appsignal/pipe.rb
appsignal-0.9.5 lib/appsignal/pipe.rb
appsignal-0.10.0.beta.0 lib/appsignal/pipe.rb
appsignal-0.9.4 lib/appsignal/pipe.rb
appsignal-0.9.3 lib/appsignal/pipe.rb
appsignal-0.9.2 lib/appsignal/pipe.rb