class SGS::RPCServer
Public Class Methods
new(channel, klass)
click to toggle source
# File lib/sgs/rpc.rb, line 57 def initialize(channel, klass) @channel = channel.to_s @klass = klass end
Public Instance Methods
start()
click to toggle source
# File lib/sgs/rpc.rb, line 62 def start puts "Starting RPC server for #{@channel}" loop do channel, request = SGS::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'] } SGS::RedisBase.redis.rpush(request['id'], MessagePack.pack(reply)) SGS::RedisBase.redis.expire(request['id'], 30) end end