Search code examples
rubycentossinatradashing

Ruby Dashing: Issues with Jobs (on a CentOS Server)


I'm having a weird event occur, where my dashing dashboard's list widget is showing erroneous data. Here's the screenshot from my live Dashing widget

Erroneous Widget

enter image description here

Expected Output

Expected Output

What follows is the code for the widget:

Code in .erb

<li data-row="1" data-col="1" data-sizex="2" data-sizey="6">
 <div data-id="facebook_insights" data-view="List" data-unordered="true" data-title="Facebook Insights: Weekly Post Views" data-moreinfo="Updated every 10 seconds"</div>
</li>

Code in job .rb

require 'mysql2'

social_count = Hash.new({ value: 0 })
time = Time.new()

date_time1 = Time.new(time.year, time.month, time.day-1)
...

SCHEDULER.every '10s' do

begin

db = Mysql.new(<HOST>,<USER>,<PASS>,<DBNAME>)

mysql1 = "SELECT <VAR> FROM <TABLE> WHERE <VAR> = '#{date_time1}' ORDER BY <VAR> DESC LIMIT 1"
...

result1 = db.query(mysql1)
...

rescue

ensure
 db.close
end

result1.each do |row|
strrow1 = row[0]
$value1 = strrow1.to_i
end
...    

social_count[0] = {label: "1:", value: $value1}
...

send_event('facebook_insights', { items: social_count.values })
end

What is really baffling, is that this code works for a similar widget using different data in the SQL query. Can anyone help me understand why?


Solution

  • I checked and re-checked the data and in my other, working code, I had my $value variables defined as $valueX with X being the number. I thought to myself "Maybe the variable names are getting confused due to them having the same name", so I changed my code to

    Working Code

    result1.each do |row|
    strrow1 = row[0]
    $variable1 = strrow1.to_i
    end
    ...    
    
    social_count[0] = {label: "1:", value: $variable1}
    

    Et Voila! Eureka! It worked. Not sure why it still got confused with the names, but from now on, my names will be unique!