Skip to content

Instantly share code, notes, and snippets.

@siyo
Created April 16, 2013 05:29
Show Gist options
  • Save siyo/5393585 to your computer and use it in GitHub Desktop.
Save siyo/5393585 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# Timeline speed plugin
#
require 'singleton'
Earthquake.once do
class TimelineSpeed
include Singleton
def initialize
@count = 0
@timer = nil
@interval = 60
end
def update(item)
return if item["event"] || item["direct_message"]
@count += 1
end
def run
EM.run do
@timer = EM.add_periodic_timer(@interval){
notify
@count = 0
}
end
end
def run?
@timer != nil
end
def notify
Earthquake.insert [ "[speed] ".c(:info),
@count.to_s,
" tweets/min".c(:info),
].join
end
end
end
Earthquake.init do
output do |item|
tls = TimelineSpeed.instance
if not tls.run?
tls.run
else
tls.update(item)
end
item
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment