我们如何监控rails app和数据库之间的连接是否已建立。如果它关闭,rails会尝试重新连接与mysql的连接吗?
答案 0 :(得分:1)
AFAIK是的,您仍然可以定期检查您要创建的特殊控制器,以显示数据库是启动还是关闭(例如,使用ActiveRecord::Base.connected?
)。
编辑3月30日星期二:
我相信您可以改为编写Metal并定期检查它的结果(使用rake任务或您习惯使用的任何监视工具):
class ConnectivityChecker
def self.call(env)
if ActiveRecord::Base.connected?
[200, { 'Content-Type' => 'text/html' }, ["Connected."]]
else
# Leave it to Rails to deal with the request.
[500, { 'Content-Type' => 'text/html' }, ['Database is not reachable.']]
end
end
end