铁轨 + TweetStream gem 重新连接
嘿,我刚刚测试了 TweetStream gem。
示例:
TweetStream::Client.new('myuser','mypass').track('ruby', 'rails') do |status|
puts "[#{status.user.screen_name}] #{status.text}"
end
这个示例有效。
问题:
- 我尝试重新启动路由器(互联网连接丢失),之后没有新消息到达。有人可以向我解释这种行为吗?
- 我测试了守护进程。如果一天或更长时间没有可用的互联网连接会发生什么?会自动重连吗?
- 我喜欢 Rufus gem(用于后台进程)。我能否以某种方式将此代码与 Rufus 集成,以检查进程是否仍处于活动状态?
我的重新连接解决方案(config/initializers/tweet_stream.rb):
client = nil
scheduler = Rufus::Scheduler.start_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
谢谢!
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:
- I tried restarting my router (internet connection lost) and after that no new messages have arrived. Can someone explain this behavior to me?
- I tested the daemon. What happens if no internet connection is available for a day or more? Will it reconnect automatically?
- 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.start_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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论