Shopify / dashing

The exceptionally handsome dashboard framework in Ruby and Coffeescript.
http://shopify.github.com/dashing/
MIT License
10.97k stars 1.18k forks source link

Widgets stopped updating #266

Open JasonEde opened 11 years ago

JasonEde commented 11 years ago

Our widgets, which have been working great for ages, have stopped updating after we tried updating our system (used gem update)

We mainly use the twitter info and twitter user (from the additonal widgets page). If I delete the history.yml then it starts up and the twitter info can pull some info

scheduler caught exception: undefined method []' for nil:NilClass /usr/local/dashing/dashboard/jobs/twitter_user.rb:19:inblock in <top (required)>' /var/lib/gems/1.9.1/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:in call' /var/lib/gems/1.9.1/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:intrigger_block' /var/lib/gems/1.9.1/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:204:in block in trigger' /var/lib/gems/1.9.1/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:incall' /var/lib/gems/1.9.1/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:in `block in trigger_job'

If I then restart dashing I get this in addition to the above.

For the twitter widget to work, you need to put in your twitter API keys in the jobs/twitter.rb file.

and nothing updates. The keys are in the file and everything was working. I feel something got broken in the updates, but I can't seem to find what.

JasonEde commented 11 years ago

I modified the twitter.rb file to added error logging to the rescue block rescue Twitter::Error => e puts "Twitter Error: #{e}" puts "\e[33mFor the twitter widget to work, you need to put in your twitter API keys in the jobs/twitter.rb file.\e[0m" end

and I now get

Twitter Error: execution expired

For the twitter widget to work, you need to put in your twitter API keys in the jobs/mentions.rb file.

moonchaser commented 11 years ago

Sorry, I didnt tie Twitter, but, I ran into the below error with other widgets

scheduler caught exception: undefined method []' for nil:NilClass

This basically means the input that is being streamed is empty and whatever method you are calling on them is erroring out. You need to handle those cases.

For example, in my meter widget I was getting the value from a file. And sometimes the value would be empty and I would get the above error because I was doing value.to_i

I changed my code to do this instead and it fixed those errors.

if value.nil?

assign default

value = -1 end output = value.to_i

JasonEde commented 11 years ago

I think I've solved this myself, by going about it a different way. I've changed the code to use the twitter API rather than page scraping. Details below... The auth checking and timeout isn't great so if anyone has hints on making that better they'd be welcome...

#### Get your twitter keys & secrets:
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
Twitter.configure do |config|
  config.consumer_key = 'YOUR_CONSUMER_KEY'
  config.consumer_secret = 'YOUR_CONSUMER_SECRET'
  config.oauth_token = 'YOUR_OAUTH_TOKEN'
  config.oauth_token_secret = 'YOUR_OAUTH_SECRET'

end

twitter_username = 'foobugs'

MAX_USER_ATTEMPTS = 10
user_attempts = 0

SCHEDULER.every '10m', :first_in => 0 do |job|
  begin
    tw_user = Twitter.user("#{twitter_username}")
    if tw_user
        tweets = tw_user.statuses_count
        followers = tw_user.followers_count
        following = tw_user.friends_count

        send_event('twitter_user_tweets', current: tweets)
        send_event('twitter_user_followers', current: followers)
        send_event('twitter_user_following', current: following)

    end
  rescue Twitter::Error => e
    user_attempts = user_attempts +1
    puts "Twitter error #{e}"
    puts "\e[33mFor the twitter_user widget to work, you need to put in your twitter API keys in the jobs/twitter_user.rb file.\e[0m"
    sleep 5
    retry if(user_attempts < MAX_USER_ATTEMPTS)
  end
end
diegodurante commented 10 years ago

I have resolved by substituting this line: followers = /([\d.]+)<\/strong> Follower/.match(response.body)[0].delete('.,').to_i

with these two: followers_count_metadata = /followers_count":[\d]+/.match(response.body) followers = /[\d]+/.match(followers_count_metadata.to_s).to_s