Class: Paraspec::MsgpackClient
- Inherits:
-
Object
- Object
- Paraspec::MsgpackClient
- Includes:
- MsgpackHelpers
- Defined in:
- lib/paraspec/msgpack_client.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MsgpackClient
constructor
A new instance of MsgpackClient.
-
#reconnect! ⇒ Object
The socket doesn’t stay operational after a fork even if the child process never uses it.
- #request(action, payload = nil) ⇒ Object
- #request_id ⇒ Object
Methods included from MsgpackHelpers
Constructor Details
#initialize(options = {}) ⇒ MsgpackClient
Returns a new instance of MsgpackClient.
8 9 10 11 12 |
# File 'lib/paraspec/msgpack_client.rb', line 8 def initialize(={}) @terminal = [:terminal] connect end |
Instance Method Details
#reconnect! ⇒ Object
The socket doesn’t stay operational after a fork even if the child process never uses it. Parent should reconnect after forking any children
34 35 36 37 |
# File 'lib/paraspec/msgpack_client.rb', line 34 def reconnect! @socket.close connect end |
#request(action, payload = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/paraspec/msgpack_client.rb', line 14 def request(action, payload=nil) req = {action: action, payload: payload, id: request_id} Paraspec.logger.debug_ipc("CliReq:#{req[:id]} #{req}") pk = packer(@socket) pk.write(req) pk.flush response = unpacker(@socket).unpack Paraspec.logger.debug_ipc("CliRes:#{req[:id]} #{response}") response = IpcHash.new.merge(response) response[:result] end |
#request_id ⇒ Object
26 27 28 29 |
# File 'lib/paraspec/msgpack_client.rb', line 26 def request_id @request_num ||= 0 "#{$$}:#{@request_num += 1}" end |