Ruby on Rails:如何在应用程序配置中设置数据库超时? [英] Ruby on Rails: How to set a database timeout in application configuration?

查看:233
本文介绍了Ruby on Rails:如何在应用程序配置中设置数据库超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的数据库设置为在设置的时间内未完成的超时请求,以防止异常请求垄断整个应用程序。

I'd like to set my database to timeout requests that do not complete within a set amount of time, in order to prevent outlier requests from monopolizing the entire application.

有什么我可以添加到我的Rails配置文件为了设置这个?

Is there anything I can add to my Rails configuration files in order to set this?

我试图添加一行我经常在网上看到 timeout:5000 到我的database.yml,但是似乎没有任何效果。

I tried to add a line I saw often online of timeout: 5000 to my database.yml, but that didn't seem to have any effect.

我试图调用在Environment.rb中的ActiveRecord :: Base.connection.execute('set statement_timeout to 5000'),但会导致Rails错误。

I tried to make calls to ActiveRecord::Base.connection.execute('set statement_timeout to 5000') in the environment.rb but that causes Rails to error out.

我在Heroku上运行了一个Postgres数据库,我没有直接的数据库访问,因此我不能直接使用数据库配置。即使我从Heroku控制台远程执行该命令,他们可以在任何时候重新启动我的应用程序,如果这不是重新执行,因为应用程序启动,我的更改丢失。

I'm running a Postgres database on Heroku, where I do not have direct database access, hence I cannot do this with database configuration directly. Even if I remotely execute that command from the Heroku console, they can restart my application at any time, and if this isn't re-executed as the application starts, my change gets lost.

推荐答案

得到这个工作,只需要包含在环境.rb的行在最后,而不是在开始或在块。

Got this working, just needed to include the line in environment.rb at the very end, rather than in the beginning or in the block.

这篇关于Ruby on Rails:如何在应用程序配置中设置数据库超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆