Created
February 17, 2010 19:50
-
-
Save subelsky/306950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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