Class: SGS::RPCServer
- Inherits:
-
Object
- Object
- SGS::RPCServer
- Defined in:
- lib/sgs/rpc.rb
Instance Method Summary collapse
-
#initialize(channel, klass) ⇒ RPCServer
constructor
A new instance of RPCServer.
- #start ⇒ Object
Constructor Details
#initialize(channel, klass) ⇒ RPCServer
Returns a new instance of RPCServer.
64 65 66 67 |
# File 'lib/sgs/rpc.rb', line 64 def initialize(channel, klass) @channel = channel.to_s @klass = klass end |
Instance Method Details
#start ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sgs/rpc.rb', line 69 def start puts "Starting RPC server for #{@channel}" loop do channel, request = RedisBase.redis.brpop(@channel) request = MessagePack.unpack(request) puts "Working on request: #{request['id']}" args = request['params'].unshift(request['method']) result = @klass.send *args reply = { 'jsonrpc' => '2.0', 'result' => result, 'id' => request['id'] } RedisBase.redis.rpush(request['id'], MessagePack.pack(reply)) RedisBase.redis.expire(request['id'], 30) end end |