【问题标题】:App won't load on heroku, can't decipher heroku logs to tell what the error is应用程序无法在 heroku 上加载,无法破译 heroku 日志来判断错误是什么
【发布时间】:2019-05-08 09:27:16
【问题描述】:

[更新:我的 comment_update_job.rb 文件中有语法错误,我现在正在排除故障] 我正在参加在线 Rails 课程,但我的应用程序突然停止工作。有人可以帮我指出正确的方向来破译heroku日志吗?

这是我的 comment_update.job.rb 文件

class CommentUpdateJob < ApplicationJob
  queue_as :default

  def perform(comment, current_user)
    ProductChannel.broadcast_to(comment.product_id, comment: render_comment(comment, current_user), average_rating: comment.product.average_rating)
  end

private

  def render_comment(comment, current_user)
    CommentsController.render(partial: 'comments/comment', locals: { comment: comment, current_user: current_user })
  end

end

这是我的heroku日志:

2018-12-06T16:09:16.954955+00:00 app[web.1]: => Booting Puma
2018-12-06T16:09:16.954980+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-12-06T16:09:16.954982+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-12-06T16:09:16.957071+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': /app/app/jobs/comment_update_job.rb:12: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
2018-12-06T16:09:16.957089+00:00 app[web.1]: end

【问题讨论】:

  • 在那之前有什么有用的吗?提出请求时会发生这种情况吗?或者,在加载应用程序时?
  • 我不这么认为。当我转到应用程序时,它告诉我它无法加载并告诉我在 heroku 日志中查找错误
  • 我认为Exiting语句之前通常会有一些错误信息。
  • 我添加了代码的顶部,我无法适应整个日志。顶部有什么帮助吗?谢谢
  • 是整个文件吗?它缺少end 和结尾。顺便说一句,我不知道你为什么拿出错误信息。它很有用,没有它,其他读者将无法获得重要信息。

标签: ruby-on-rails ruby heroku ruby-on-rails-5


【解决方案1】:

在您编辑问题之前,您展示了:

class CommentUpdateJob < ApplicationJob
  queue_as :default

  def perform(comment, current_user)
    ProductChannel.broadcast_to(comment.product_id, comment: render_comment(comment, current_user), average_rating: comment.product.average_rating)
  end

  private

  def render_comment(comment, current_user)
    CommentsController.render(partial: 'comments/comment', locals: { comment: comment, current_user: current_user })
  end

缺少end。应该是:

class CommentUpdateJob < ApplicationJob
  queue_as :default

  def perform(comment, current_user)
    ProductChannel.broadcast_to(comment.product_id, comment: render_comment(comment, current_user), average_rating: comment.product.average_rating)
  end

  private

  def render_comment(comment, current_user)
    CommentsController.render(partial: 'comments/comment', locals: { comment: comment, current_user: current_user })
  end

end

顺便说一句,在我的config/environments/development.rb,我喜欢设置:

config.eager_load = true

这将花费您启动时间。但是,它会在您的生产环境和开发环境之间创建更紧密的匹配,并且通常会导致在开发中抛出错误,否则在您部署到 Heroku 之前不会抛出这些错误。 IMO,开发中的额外启动时间不仅仅是通过节省 Heroku 上部署失败的时间来弥补的。

【讨论】:

    【解决方案2】:

    没见过这个错误,不过我觉得可能还是路由问题,或者redis数据库缺少插件。

    我建议您将 PostgreSQL 与 heroku 平台一起使用,它集成得非常好,并且有一个免费的 Hobbistic 版本,可让您测试并充分使用您的应用程序进行登台。

    在您的 heroku 仪表板中查找 ENV_VARIABLES(例如开发/生产模式等)。

    希望这个东西可以帮到你:)

    【讨论】:

    • 我以为我在使用 Postgres,有什么表明我不是吗?
    猜你喜欢
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    相关资源
    最近更新 更多