Class: AmazonAlexa
Overview
Amazon Alexa Logger
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ AmazonAlexa
constructor
A new instance of AmazonAlexa.
- #log(req, res) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ AmazonAlexa
Returns a new instance of AmazonAlexa.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/botanalytics/amazon.rb', line 7 def initialize(params = {}) super(params) @path = 'messages/amazon-alexa/' @async = params.fetch(:async, false) informs("Logging enabled for #{self.class.name}...") if @async require 'concurrent' @executor_service = Concurrent::ThreadPoolExecutor.new( min_threads: 1, max_threads: Concurrent.processor_count * 2, max_queue: Concurrent.processor_count * 1000, fallback_policy: :caller_runs ) informs("Mode: Async...") end end |
Instance Method Details
#log(req, res) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/botanalytics/amazon.rb', line 24 def log(req, res) validation = validate(req, res) if validation[:ok] payload = {:request => req, :response => res} informs("Logging messages...") informs(payload) if @async @executor_service.post do submits(payload, @path) end else submits(payload, @path) end else fails(validation[:err], validation[:reason], {:request => req, :response => res}) end end |