Class: GoogleAssistant
Overview
GoogleAsistant Logger
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ GoogleAssistant
constructor
A new instance of GoogleAssistant.
- #log(req, res) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ GoogleAssistant
Returns a new instance of GoogleAssistant.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/botanalytics/google.rb', line 7 def initialize(params = {}) super(params) @path = 'messages/google-assistant/' @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, max_queue: 100, fallback_policy: :caller_runs ) informs("Mode: Async...") end end |
Instance Method Details
#log(req, res) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/botanalytics/google.rb', line 26 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 |