Sha256: 2747ffb8ddc86a04b069fdcdac78de3d264a764c901c84f86e1a64c8f7f615ba

Contents?: true

Size: 1.16 KB

Versions: 37

Compression:

Stored size: 1.16 KB

Contents

require "ostruct"
require "thread"

require "protobuf/nats"

module Protobuf
  module Nats
    class Runner
      include ::Protobuf::Logging

      def initialize(options)
        @options = case
                   when options.is_a?(OpenStruct) then
                     options.marshal_dump
                   when options.respond_to?(:to_hash) then
                     options.to_hash.symbolize_keys
                   else
                     fail "Cannot parse Nats Server - server options"
                   end
      end

      def run
        @server = ::Protobuf::Nats::Server.new(@options)
        register_signals
        @server.run do
          yield if block_given?
        end
      end

      def running?
        @server.try :running?
      end

      def stop
        @server.try :stop
      end

      private

      def register_signals
        trap(:TRAP) do
          ::Thread.list.each do |thread|
            logger.info do
              <<-THREAD_TRACE
                #{thread.inspect}:
                  #{thread.backtrace.try(:join, $INPUT_RECORD_SEPARATOR)}"
              THREAD_TRACE
            end
          end
        end

      end
    end

  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
protobuf-nats-0.10.8 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.7 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.6 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.5 lib/protobuf/nats/runner.rb
protobuf-nats-0.12.0.pre0 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.4 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.3 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.3.pre0 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.2 lib/protobuf/nats/runner.rb
protobuf-nats-0.11.0.pre1 lib/protobuf/nats/runner.rb
protobuf-nats-0.11.0.pre0 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.1 lib/protobuf/nats/runner.rb
protobuf-nats-0.10.0 lib/protobuf/nats/runner.rb
protobuf-nats-0.9.0 lib/protobuf/nats/runner.rb
protobuf-nats-0.9.0.pre3 lib/protobuf/nats/runner.rb
protobuf-nats-0.9.0.pre2 lib/protobuf/nats/runner.rb
protobuf-nats-0.9.0.pre1 lib/protobuf/nats/runner.rb
protobuf-nats-0.8.0 lib/protobuf/nats/runner.rb
protobuf-nats-0.7.0 lib/protobuf/nats/runner.rb
protobuf-nats-0.7.0.pre1 lib/protobuf/nats/runner.rb