错误读取文件-ENOENT:此类文件或目录@ rb_sysopen

时间:2020-06-15 04:08:44

标签: ruby dashing

我刚刚开始研究粉碎(以前称为破折号)。

根据此处的网址https://github.com/Shopify/dashing/wiki/Dashing-Workshop

我想做的只是从本地文件中简单读取。

本地文件位于其他目录(名为googlestatus)中,并且包含:

connected

jobs / ops.orb包含:

gstatus = puts File.read(./status/googlestatus)

############ scheduler
SCHEDULER.every '1s', :first_in => 0 do |job|
  send_event('response_time', { value: gstatus })
end

但是当我运行smashing start时,它给了我以下错误:

Arrived
bundler: failed to load command: thin (/usr/local/bin/thin)
Errno::ENOENT: No such file or directory @ rb_sysopen - googlestatus
  /home/test/monitorama/monitorama/jobs/test-r.rb:3:in `initialize'
  /home/test/monitorama/monitorama/jobs/test-r.rb:3:in `open'
  /home/test/monitorama/monitorama/jobs/test-r.rb:3:in `get_file_as_string'
  /home/test/monitorama/monitorama/jobs/test-r.rb:12:in `<top (required)>'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing/app.rb:170:in `require'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing/app.rb:170:in `block in require_glob'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing/app.rb:169:in `each'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing/app.rb:169:in `require_glob'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing/app.rb:180:in `<top (required)>'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing.rb:3:in `require'
  /var/lib/gems/2.7.0/gems/smashing-1.3.0/lib/dashing.rb:3:in `<top (required)>'
  config.ru:1:in `require'
  config.ru:1:in `block in <main>'
  /var/lib/gems/2.7.0/gems/rack-2.2.2/lib/rack/builder.rb:125:in `instance_eval'
  /var/lib/gems/2.7.0/gems/rack-2.2.2/lib/rack/builder.rb:125:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `eval'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `load'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/thin/controllers/controller.rb:72:in `start'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/thin/runner.rb:203:in `run_command'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/lib/thin/runner.rb:159:in `run!'
  /var/lib/gems/2.7.0/gems/thin-1.7.2/bin/thin:6:in `<top (required)>'
  /usr/local/bin/thin:23:in `load'
  /usr/local/bin/thin:23:in `<top (required)>'

1 个答案:

答案 0 :(得分:0)

您的代码有些错误:

  • 您需要在文件的代码中用引号将文件名括起来,即:
    puts File.read("./status/googlestatus")
    
  • 现在,您(尝试)在启动过程中仅读取文件内容一次。然后,它一次读取的值将每秒钟发送一次,而无需再次读取。您可能希望将文件的读取放入计划的块中。
  • 最后,似乎您尝试读取的文件在启动过程中还不存在。