Sha256: d9e93811aba3c34fc895decba551ab4abba8fec591cc345776f6549b36685b0a

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require 'ostruct'

module Protobuf
  module Rpc
    class ZmqRunner
      include ::Protobuf::Logger::LogMethods

      def initialize(options)
        @options = case
                   when options.is_a?(OpenStruct) then
                     options.marshal_dump
                   when options.respond_to?(:to_hash) then
                     options.to_hash
                   else
                     raise "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(:TTIN) do
          @server.add_worker
          log_info { "Increased worker size to: #{@server.total_workers}" }
        end

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

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
protobuffy-3.6.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuffy-3.5.1 lib/protobuf/rpc/servers/zmq_runner.rb
protobuffy-3.4.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuffy-3.3.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuffy-3.2.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuffy-3.1.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.2.1 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.2.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.1.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.5 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.4 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.3 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.2 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.1 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.0 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.0.rc2 lib/protobuf/rpc/servers/zmq_runner.rb
protobuf-3.0.0.rc1 lib/protobuf/rpc/servers/zmq_runner.rb