Sha256: abfd933455a609b1b011075fd957950c492cea53b704425792809b35070d5396

Contents?: true

Size: 1.47 KB

Versions: 17

Compression:

Stored size: 1.47 KB

Contents

require 'ostruct'
require 'thread'

module Protobuf
  module Rpc
    class ZmqRunner
      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 parser Zmq Server - server options"
                   end
      end

      def run
        @server = ::Protobuf::Rpc::Zmq::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

        trap(:TTIN) do
          @server.add_worker
          logger.info { "Increased worker size to: #{@server.total_workers}" }
        end

        trap(:TTOU) do
          logger.info { "Current worker size: #{@server.workers.size}" }
          logger.info { "Current busy worker size: #{@server.busy_worker_count}" }
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
protobuf-3.6.12 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.11 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.10 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.7.0.pre2 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.9 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.7.0.pre1 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.7.0.pre0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.7 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.6 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.2 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.1 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.6.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.5.5 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.5.4 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.5.3 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.5.2 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.5.1 lib/protobuf/rpc/servers/zmq_runner.rb