开发者

Rails + TweetStream gem reconnecting

Hey, I just tested the TweetStream gem.

Example:

TweetStream::Client.new('myuser','mypass').track('ruby', 'rails') do |status|  
 puts "[#{status.user.screen_name}] #{status.text}" 
end

This example works.

Questions:

  1. I tried restarting my router (internet connection lost) and after that no new messages have arrived. Can someone explain this behavior to me?
  2. I tested the daemon. What happens if no internet connection is available for a day or more? Will it reconnect automatically?
  3. I like Rufus gem (for background processes). Can I somehow integrate this code with Rufus where I would check if the process is still active?

My reconnect solution (config/initializers/tweet_stream.rb):

client = nil
scheduler = Rufus::Scheduler.st开发者_如何学JAVAart_new
scheduler.every '30min', :first_in => '1s' do |job|
  client.stop rescue nil
  client = TweetStream::Client.new('user','pass').on_error do |message|
    Rails.logger.info "[Rufus][#{Time.now}] TweetStream error: #{message}"
  end.track('love') do |status|
    Rails.logger.error "[TweetStream] Status: #{status.id}"
  end
end

Thx!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜