2016-09-12 4 views
0

監視のためにダッシュボードDashingを設定しようとしています。ダッシュボードウィジェットを作成するために使用されるデータは、Oracleデータベースから取得されます。威勢がインストールされていて、テストダッシュボードが正常に動作しているが、私はダッシュの起動に失敗したOracleインスタンスからのデータとウィジェットを取り込むために自分の仕事を作成したとき、次のエラーが新しい定義されていないローカル変数またはメソッド `conn 'for main:Object(NameError)on Dashing start

<pre>/home/{home}/dashboard/jobs/new.rb:25:in `<top (required)>': undefined local variable or method `conn' for main:Object (NameError) 
    from /usr/local/lib/ruby/gems/2.0.0/gems/backports-3.6.8/lib/backports/std_lib.rb:9:in `require' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/backports-3.6.8/lib/backports/std_lib.rb:9:in `require_with_backports' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing/app.rb:171:in `block in require_glob' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing/app.rb:170:in `each' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing/app.rb:170:in `require_glob' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing/app.rb:181:in `<top (required)>' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing.rb:3:in `require' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/dashing-1.3.7/lib/dashing.rb:3:in `<top (required)>' 
    from config.ru:1:in `require' 
    from config.ru:1:in `block in <main>' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize' 
    from config.ru:1:in `new' 
    from config.ru:1:in `<main>' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/rack/adapter/loader.rb:33:in `eval' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/rack/adapter/loader.rb:33:in `load' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/controllers/controller.rb:182:in `load_rackup_config' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/controllers/controller.rb:72:in `start' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/runner.rb:200:in `run_command' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/runner.rb:156:in `run!' 
    from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.6.4/bin/thin:6:in `<top (required)>' 
    from /usr/local/bin/thin:23:in `load' 
    from /usr/local/bin/thin:23:in `<main>'</pre> 

Rubyコードを(表示されています.RB)

<pre>require 'rubygems' 
require 'oci8' 

# :first_in sets how long it takes before the job is first run. In this case, it is run immediately 
SCHEDULER.every '15m', :first_in => 0 do |job| 

tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {ORACLE_SERVER})(PORT = 1521)) (CONNECT_DATA = (SID = {SID})))' 

conn = OCI8.new('{USER}', '{PASS}', tnsname) 

last_value = rowitem 

cursor = conn.parse("SELECT count(status) AS status_count FROM generation WHERE billcycle is NULL AND status = '13'") 
cursor.define(1, Integer) 
cursor.exec() 
rowitem = [] 

while r = cursor.fetch() 
     rowitem = r 
end 

send_event('new', { current: rowitem, last: last_value }) 
cursor.close() 
end 
conn.logoff</pre> 

スケジューラ&のsend_event線をランをコメントアウトされているスクリプトを手動で実行することを可能にすると期待どおりの結果が返されます。

これはRubyを初めて使用しているので間違いがありませんが、誰でもこの機能を有効にすることができれば幸いです。

答えて

0

エラーメッセージはあなたが知る必要があるすべてを伝えます:conn変数はライン25上で、定義されていない:あなたはブロックの範囲内connを定義し

SCHEDULER.every '15m', :first_in => 0 do |job| 
    # ... 

    conn = OCI8.new('{USER}', '{PASS}', tnsname) 

    # ... 
end 

conn.logoff 

、それにアクセスしようとしました外部から。それは変数がどのように機能するかではなく、定義された場所の外部からアクセスすることはできません。

些細な修正は、ブロック内logoffメソッド呼び出しを上に移動することです:答えは顔であなたを見つめので簡単ですされたとき、私はそれを愛する

SCHEDULER.every '15m', :first_in => 0 do |job| 
    # ... 

    conn = OCI8.new('{USER}', '{PASS}', tnsname) 

    # ... 

    conn.logoff 
end 
+0

。私の防衛では、私はこのhttps://github.com/Shopify/dashing/issues/344を使ってルビースクリプトを構築していました。 rowitem = 0をトップに追加するだけで、すべての作業が完了しました。助けをお祈りします。 –

関連する問題