Permalink
Browse files

Merge pull request #19 from christopherjkim/steamlogins

Stream update task now logs exceptions.
  • Loading branch information...
2 parents 69ad6cc + 6e05a90 commit 04f48a37a97415a22c0b1fa24159390af92e9330 @kixelated committed Mar 6, 2012
Showing with 19 additions and 6 deletions.
  1. +19 −6 app/models/stream.rb
View
@@ -9,16 +9,29 @@ class Stream < ActiveRecord::Base
validates_inclusion_of :provider, :in => PROVIDERS.values
def update_status
+ current_viewers = nil
+ current_status = nil
+ is_live = false
if self.provider == "justintv"
response = HTTParty.get("http://api.justin.tv/api/stream/list.xml?channel=#{identifier}")
- current_viewers = response["streams"]["stream"]["channel_count"] rescue nil
- current_status = response["streams"]["stream"]["channel"]["status"] rescue nil
- self.update_attributes(:viewers => current_viewers, :live => !!current_viewers, :status => current_status)
+ begin
+ current_viewers = response["streams"]["stream"]["channel_count"]
+ current_status = response["streams"]["stream"]["channel"]["status"]
+ rescue Exception => e
+ logger.error e
+ ensure
+ self.update_attributes(:viewers => current_viewers, :live => !!current_viewers, :status => current_status)
+ end
elsif self.provider == "own3dtv"
response = HTTParty.get("http://api.own3d.tv/liveCheck.php?live_id=#{identifier}")
- current_viewers = response["own3dReply"]["liveEvent"]["liveViewers"] rescue nil
- is_live = response["own3dReply"]["liveEvent"]["isLive"] rescue false
- self.update_attributes(:viewers => current_viewers, :live => is_live)
+ begin
+ current_viewers = response["own3dReply"]["liveEvent"]["liveViewers"]
+ is_live = response["own3dReply"]["liveEvent"]["isLive"]
+ rescue Exception => e
+ logger.error e
+ ensure
+ self.update_attributes(:viewers => current_viewers, :live => is_live)
+ end
end
end

0 comments on commit 04f48a3

Please sign in to comment.