Skip to content
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

use twitter-stream's reconnect-on-timeout behaviour #141

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion earthquake.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_runtime_dependency "twitter-stream"
s.add_runtime_dependency "twitter-stream", "~> 0.1.16"
s.add_runtime_dependency "notify"
s.add_runtime_dependency "i18n"
s.add_runtime_dependency "activesupport"
Expand Down
16 changes: 1 addition & 15 deletions lib/earthquake/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def default_config
confirm_type: :y,
expand_url: false,
thread_indent: " ",
no_data_timeout: 30
}
end

Expand Down Expand Up @@ -142,29 +141,17 @@ def start(options = {})
end

EM.add_periodic_timer(config[:output_interval]) do
if @last_data_received_at && Time.now - @last_data_received_at > config[:no_data_timeout]
begin
reconnect
rescue EventMachine::ConnectionError => e
# ignore
end
end
if Readline.line_buffer.nil? || Readline.line_buffer.empty?
sync { output }
end
end

reconnect unless options[:'no-stream'] == true
start_stream(config[:api]) unless options[:'no-stream'] == true

trap('INT') { stop }
end
end

def reconnect
item_queue.clear
start_stream(config[:api])
end

def start_stream(options)
stop_stream

Expand All @@ -178,7 +165,6 @@ def start_stream(options)
@stream = ::Twitter::JSONStream.connect(options)

@stream.each_item do |item|
@last_data_received_at = Time.now # for reconnect when no data
item_queue << JSON.parse(item)
end

Expand Down