lib/chillout/client.rb in chillout-0.8.2 vs lib/chillout/client.rb in chillout-0.8.3

- old
+ new

@@ -1,11 +1,10 @@ require 'forwardable' require 'chillout/server_side/server_side' require 'chillout/server_side/http_client' require 'chillout/server_side/dispatcher' require 'chillout/config' -require 'chillout/event_data_builder' require 'chillout/prefixed_logger' require 'chillout/worker' require 'chillout/check_result' require 'thread' @@ -25,18 +24,18 @@ yield @config if block_given? @logger = PrefixedLogger.new("Chillout", @config.logger) @http_client = HttpClient.new(@config, logger).freeze - @event_data_builder = EventDataBuilder.new(@config).freeze - @server_side = ServerSide.new(@event_data_builder, @http_client).freeze + @server_side = ServerSide.new(@config, @http_client).freeze @dispatcher = Dispatcher.new(@server_side).freeze case @config.strategy when :thread @queue = Queue.new @worker_mutex = Mutex.new @worker_thread = nil + @max_queue = config.max_queue when :active_job require 'chillout/job' Chillout::Job.dispatcher = @dispatcher end end @@ -47,19 +46,23 @@ start_worker when :active_job end end - def enqueue(creations) + def enqueue(metrics) case @config.strategy when :thread start_worker - @logger.debug "Creations were enqueued." - @queue << creations + if @queue.size < @max_queue + @queue << metrics + @logger.debug "Metrics were enqueued." + else + @logger.error "Metrics buffer overflow. Skipping enqueue." + end when :active_job - @logger.debug "Creations were enqueued." - Chillout::Job.perform_later(YAML.dump(creations)) + Chillout::Job.perform_later(YAML.dump(metrics)) + @logger.debug "Metrics were enqueued." end end def worker_running? @worker_thread && @worker_thread.alive? @@ -68,10 +71,10 @@ def start_worker return if worker_running? @worker_mutex.synchronize do return if worker_running? @worker_thread = Thread.new do - worker = Worker.new(@dispatcher, @queue, @logger) + worker = Worker.new(@max_queue, @dispatcher, @queue, @logger) worker.run end end end