Class: RedisRpc::Logic
- Inherits:
-
Object
- Object
- RedisRpc::Logic
- Defined in:
- lib/redis_rpc/logic.rb
Instance Attribute Summary collapse
-
#res ⇒ Object
Returns the value of attribute res.
Instance Method Summary collapse
- #exec(args, timeout) ⇒ Object
-
#initialize(url, callback, channel, logger, parser) ⇒ Logic
constructor
A new instance of Logic.
Constructor Details
#initialize(url, callback, channel, logger, parser) ⇒ Logic
Returns a new instance of Logic.
8 9 10 11 12 13 14 |
# File 'lib/redis_rpc/logic.rb', line 8 def initialize(url, callback, channel, logger, parser) @redis = Redis.new(url: url) @logger = logger @res = Response.new(@redis, channel, logger, parser) @callback = callback @parser = parser end |
Instance Attribute Details
#res ⇒ Object
Returns the value of attribute res.
6 7 8 |
# File 'lib/redis_rpc/logic.rb', line 6 def res @res end |
Instance Method Details
#exec(args, timeout) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/redis_rpc/logic.rb', line 16 def exec(args, timeout) begin _args = @parser.parse(args) logger.error(ArgumentError.new("miss method name or uuid")) and return if _args[:uuid].nil? || _args[:method].nil? result = @callback.send(_args[:method], *_args[:params]) @res.publish({uuid: _args[:uuid], _method: _args[:method], result: result}, timeout) rescue Exception => e if defined?(_args) && !_args.nil? @res.catch(_args[:uuid], e) else @logger.error(e) end end rescue Exception => e @logger.error(e) end |