Created
April 16, 2013 05:29
-
-
Save siyo/5393585 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
# -*- 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