Ruby on Rails:如何在应用程序配置中设置数据库超时?

编程入门 行业动态 更新时间:2024-10-23 17:28:39
本文介绍了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:如何在应用程序配置中设置数据库超时?

本文发布于:2023-10-25 22:12:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   数据库   如何在   Ruby   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!