Created
March 13, 2012 18:52
-
-
Save kylev/2030717 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
timed_loop_batch(0.25, 1000, 100) do |batch_size| | |
changed = GiantMetric.connection.update_sql("DELETE FROM giant_metrics WHERE created_at <= #{1.month.ago} LIMIT #{batch_size}") | |
break if changed < batch_size | |
end |
This file contains hidden or 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
def timed_batch_loop(target_secs, start_size, step, min_size=1, max_size=nil) | |
current = start_size | |
loop do | |
start_time = Time.now | |
yield current | |
if Time.now - start_time > target_secs | |
current = [min_size, current - step].max | |
else | |
if max_size | |
current = [max_size, current + step].min | |
else | |
current += step | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment