我想将我的数据库设置为在设置的时间内未完成的超时请求,以防止异常请求垄断整个应用程序。
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:如何在应用程序配置中设置数据库超时?
发布评论