lib/instrumental/agent.rb in instrumental_agent-0.5.1 vs lib/instrumental/agent.rb in instrumental_agent-0.6.0
- old
+ new
@@ -9,13 +9,13 @@
# Instrumental::Agent.new(API_KEY)
module Instrumental
class Agent
BACKOFF = 2.0
MAX_RECONNECT_DELAY = 15
- MAX_BUFFER = 100
+ MAX_BUFFER = 5000
- attr_accessor :host, :port
+ attr_accessor :host, :port, :synchronous
attr_reader :connection, :enabled
def self.logger=(l)
@logger = l
end
@@ -148,11 +148,13 @@
end
cmd = "%s %s\n" % [cmd, args.collect(&:to_s).join(" ")]
if @queue.size < MAX_BUFFER
logger.debug "Queueing: #{cmd.chomp}"
+ @main_thread = Thread.current if @synchronous
@queue << cmd
+ Thread.stop if @synchronous
cmd
else
logger.warn "Dropping command, queue full(#{@queue.size}): #{cmd.chomp}"
nil
end
@@ -199,9 +201,10 @@
else
logger.debug "Sending: #{command_and_args.chomp}"
@socket.puts command_and_args
command_and_args = nil
end
+ @main_thread.run if @synchronous
end
rescue Exception => err
logger.error err.to_s
if command_and_args
logger.debug "requeueing: #{command_and_args}"