-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creates batch adapter #58
Conversation
@wjordan: Here's a quick spike. One issue (seemingly present in all the queueing/buffer code I looked at) is: how/when to trigger the "final" flushing of the buffer. I've added a method called |
@tpitale Awesome progress! This looks feasible. Flushing a partially-filled buffer can be handled a few different ways:
the last one is already covered by the existing FLUSH_OBJECT = Object.new.freeze
def clear(final=false)
@queue << FLUSH_OBJECT
if final
@flushing_thread.kill
@flushing_thread.join
flush(true)
end
end
def flush(final=false)
param_array = []
while param_array.size < @size && (object = @queue.deq(final)) != FLUSH_OBJECT
param_array << object
end
rescue ThreadError
ensure
@adapter.post(param_array)
end
end |
Okay, so you're thinking the use case would be to flush it at the end of a request, so that N events would get queued up and make a minimal number of calls to Google. I think I can make some tweaks to make that work. |
@tpitale i commend how long you've been working on this thing! it has really help us out in our usecase (analytics for an iframe embed interactive widget, frontend analytics is being blocked) |
@adapter = adapter.new(Staccato.ga_batch_uri) | ||
|
||
@queue = SizedQueue.new(@size) | ||
@flushing_thread = Thread.new { loop { perform_flush; sleep(flush_timeout) } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bots-business I could change this PR so that no flushing_thread
is created if the flush_timeout
is explicitly set to nil
. This way the tracker and adapter are still thread-safe, but no additional thread is created to perform auto-flushing of the queue.
Closing this as old and not sure it's necessary yet in V4. |
SizedQueue
for thread-safe queueingTODO:
clear
behaviorResolves #57