Class: RedisRpc::Response
- Inherits:
-
Object
- Object
- RedisRpc::Response
- Defined in:
- lib/redis_rpc/response.rb
Instance Method Summary collapse
- #catch(uuid, e) ⇒ Object
-
#initialize(redis, channel, logger, parser) ⇒ Response
constructor
A new instance of Response.
- #publish(request, timeout) ⇒ Object
- #sync_callback(args, timeout = 5) ⇒ Object
Constructor Details
#initialize(redis, channel, logger, parser) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 |
# File 'lib/redis_rpc/response.rb', line 9 def initialize(redis, channel, logger, parser) @redis = redis @channel = channel @logger = logger @parser = parser end |
Instance Method Details
#catch(uuid, e) ⇒ Object
28 29 30 31 32 |
# File 'lib/redis_rpc/response.rb', line 28 def catch(uuid, e) @logger.error("#{uuid}: #{e}") request_str = @parser.pack({uuid: uuid, error: e}.to_json) @redis.publish(@channel, request_str) end |
#publish(request, timeout) ⇒ Object
16 17 18 19 20 |
# File 'lib/redis_rpc/response.rb', line 16 def publish(request, timeout) request_str = @parser.pack(request.to_json) @redis.publish(@channel, request_str) SyncHandler.new(@redis, request[:uuid], request[:method], @parser.secret_key, timeout) end |
#sync_callback(args, timeout = 5) ⇒ Object
22 23 24 25 26 |
# File 'lib/redis_rpc/response.rb', line 22 def sync_callback(args, timeout=5) # {uuid: uuid, _method: method, result: result, error: error} @redis.set(args[:uuid], @parser.pack(args.to_json)) @redis.expire(args[:uuid], timeout.to_i) end |