【问题标题】:error reading file - ENOENT: No such file or directory @ rb_sysopen错误读取文件 - ENOENT:没有这样的文件或目录@rb_sysopen
【发布时间】:2020-06-15 20:43:25
【问题描述】:

我刚开始探索粉碎(以前称为 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

但是当我运行粉碎启动时,它给了我以下错误:

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)>'

【问题讨论】:

    标签: ruby dashing


    【解决方案1】:

    您的代码有几个问题:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 2018-05-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 2018-08-12
      相关资源
      最近更新 更多