Skip to content

Commit

Permalink
Add support for (off by default) autotruncation to avoid needing an e…
Browse files Browse the repository at this point in the history
…xternal trigger. Not recommended.
  • Loading branch information
noahhl committed May 27, 2012
1 parent 8cdc429 commit e71e514
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.yml
Expand Up @@ -8,3 +8,4 @@ retentions:
10: 360 #1 hour
60: 10080 #1 week
600: 52594 #1 year
autotruncate: false
18 changes: 18 additions & 0 deletions lib/batsd/receiver.rb
Expand Up @@ -6,6 +6,7 @@ module Batsd
#
module Receiver


# Exposes registered handlers
def self.handlers
@handlers
Expand Down Expand Up @@ -47,6 +48,12 @@ def receive_data(msg)
#
class Daemon

# Force a truncation at all intervals at least every
# MAX_TRUNCATION_INTERVAL seconds. This prevents overflow issues in
# EventMachine, but is largely theoretical; it's unlikely any instance of
# the daemon would run this long.
MAX_TRUNCATION_INTERVAL = 2000000

# Create a new daemon and set up it's options and
# register the handlers provided
#
Expand Down Expand Up @@ -86,6 +93,17 @@ def run
end
end

if @options[:autotruncate]
puts "Enabling autotruncation"
@options[:retentions].each do |interval, n|
frequency = [interval.to_i * n.to_i, MAX_TRUNCATION_INTERVAL].min
EventMachine.add_periodic_timer(frequency) do
Thread.new { Batsd::Truncator.new(@options).run(interval) }
end
puts "Truncator added for #{interval} second aggregations every #{frequency} seconds"
end
end

end
end

Expand Down

0 comments on commit e71e514

Please sign in to comment.