class Praetor::ServiceClient
Attributes
redis[RW]
service_endpoint[RW]
Public Class Methods
new(service_endpoint)
click to toggle source
# File lib/praetor/service_client.rb, line 8 def initialize(service_endpoint) @service_endpoint = service_endpoint client_options = ENV['REDIS_PROVIDER'] ? { url: ENV['REDIS_PROVIDER'] } : {} @redis = Redis.new client_options end
Public Instance Methods
request(path, params = {})
click to toggle source
# File lib/praetor/service_client.rb, line 15 def request(path, params = {}) path_parts = path.split '#' req = { 'key' => Rubyflake.generate.to_s(32), 'controller' => "#{path_parts.first.camelize}Controller", 'action' => path_parts.last, 'params' => params } redis.lpush service_endpoint, JSON.generate(req) _, response = redis.brpop req['key'] parsed_response = Hashie::Mash.new JSON.parse(response) if parsed_response.status == 'ok' parsed_response.data else raise "Service error: #{parsed_response.data.message} #{parsed_response.data.backtrace.join("\n")}" end end
stop_service()
click to toggle source
Used primarily during testing to stop the run loop of a service
# File lib/praetor/service_client.rb, line 36 def stop_service redis.lpush service_endpoint, 'stop' end