Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在ruby中使用CustomHealthCheck和health\u check gem?_Ruby On Rails_Rubygems - Fatal编程技术网

Ruby on rails 如何在ruby中使用CustomHealthCheck和health\u check gem?

Ruby on rails 如何在ruby中使用CustomHealthCheck和health\u check gem?,ruby-on-rails,rubygems,Ruby On Rails,Rubygems,从health\u check官方网站,我们知道它可以在配置文件中添加config.add\u custom\u check块: 但是关于CustomHealthCheck类,如何定义它呢 对于okcomputergem,它提供了如下方式: 运行curl-v localhost:3000/health\u check.json,获得: {"healthy":false,"message":"health_check failed: undefined method `perform_chec

health\u check
官方网站,我们知道它可以在配置文件中添加
config.add\u custom\u check
块:

但是关于
CustomHealthCheck
类,如何定义它呢

对于
okcomputer
gem,它提供了如下方式:

运行curl-v localhost:3000/health\u check.json,获得:

{"healthy":false,"message":"health_check failed: undefined method `perform_check' for CustomHealthCheck:Class"}%

更新2 在
config/initializers/health\u check.rb
中编辑源代码:

class CustomHealthCheck
  def self.perform_check
    p 'OK'
  end
end

HealthCheck.setup do |config|
...
得到:


成功是通过返回空字符串或空字符串来定义的。现在,您的
perform\u check
总是返回字符串“OK”,这将被视为失败

尝试以下操作以通过健康检查:

class CustomHealthCheck
  def self.perform_check
    everything_is_good = true # or call some method to do more elaborate checking
    return everything_is_good ? "" : "We've got Problems"
  end
end

不清楚你们的目标和问题是什么。您可能想发布一些代码,其中您尝试使用此代码时出现了错误。@mahemoff我不知道如何编写代码,所以问了它。当然可以,但不清楚您到底想实现什么。示例中的CustomHealthCheck只是一个虚构的类。@mahemoff谢谢。我已更新了问题并粘贴了我尝试的内容。您已将
perform\u check
定义为实例方法。如果你想让它成为一个类方法,你需要做
def self.perform\u check
。在我尝试了你的代码之后,它得到了:
{“health”:false,“health\u check failed:no implicit conversion of true to String”}%
@zseikyocho-我更正了我的错误,所以它现在总是返回一个字符串
{"healthy":false,"message":"health_check failed: undefined method `perform_check' for CustomHealthCheck:Class"}%
class CustomHealthCheck
  def self.perform_check
    p 'OK'
  end
end

HealthCheck.setup do |config|
...
{"healthy":false,"message":"health_check failed: OK"}%
class CustomHealthCheck
  def self.perform_check
    everything_is_good = true # or call some method to do more elaborate checking
    return everything_is_good ? "" : "We've got Problems"
  end
end