Rufus scheduler syntax error

49 views Asked by At

Original code:

require 'oci8'

SCHEDULER.every '10s', :first_in => 0 do |job|
  begin
    conn = OCI8.new('apps','apps');
    mylist = Hash.new
    conn.exec("select full_name, count(*) from per_all_people_f
               where rownum < 6 group by first_name") do |r|
      mylist[r[0]] = { label: r[0], value: r[1].to_i.to_s }
    end
    send_event('emp-list', { items: mylist.values })
    conn.logoff
  rescue Exception => e
    puts e.message
  end
end

Running ruby oratest1.rb gives following errors:

oratest1.rb:11: syntax error
      mylist[r[0]] = { label: r[0], value: r[1].to_i.to_s }
                             ^
oratest1.rb:11: syntax error
      mylist[r[0]] = { label: r[0], value: r[1].to_i.to_s }
                                          ^
oratest1.rb:11: syntax error
oratest1.rb:13: syntax error
    send_event('emp-list', { items: mylist.values })
                                   ^
oratest1.rb:13: syntax error
    send_event('emp-list', { items: mylist.values })
                                                   ^
oratest1.rb:17: syntax error
  rescue Exception => e
        ^
oratest1.rb:21: syntax error
2

There are 2 answers

0
Michel Boaventura On

You are probably using ruby 1.8. This hash syntax was included on 1.9 onwards.

To make sure, run ruby -v and check the output.

0
Arslan Ali On

If you using ruby prior to 1.9, you must use the following syntax for hashes:

mylist[r[0]] = { :label => r[0], :value => r[1].to_i.to_s }

The syntax that you are using is valid in ruby 1.9 and onwards!