Skip to content

Instantly share code, notes, and snippets.

@subelsky
Created February 17, 2010 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subelsky/306950 to your computer and use it in GitHub Desktop.
Save subelsky/306950 to your computer and use it in GitHub Desktop.
class Tracker
def track_event(a,b,c)
@queue ||= Queue.new
start_pushing_thread
hash = { :a => a, :b =>, :c => c }
@queue << hash
end
private
def start_pushing_thread
return if @pushing_thread
@pushing_thread = Thread.new do
items = []
loop do
# pop will block until there are queue items available
items << @queue.pop
if items.size > 24
SdbWrapper::batch_log_to_sdb(items,'tracking_domain')
items.clear
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment