[英]Cancel Rails DB connection
I am writing an app that uses Server Side events with ActionController::Live. 我正在编写一个使用Server Side事件与ActionController :: Live的应用程序。 It is using the puma app server.
它使用的是puma app服务器。 A method in the Messages controller stays alive while the user is connected waiting for messages from Redis.
当用户连接等待来自Redis的消息时,Messages控制器中的方法保持活动状态。
The problem is that I don't want to connect to Postgres on this method. 问题是我不想在这种方法上连接到Postgres。 After I open the app in six tabs it has over five connections defined by the pool size in the
config/database.yml
file and the app crashes. 在六个选项卡中打开应用程序后,它在
config/database.yml
文件中有超过五个由池大小定义的连接,并且应用程序崩溃。
Is there anyway to tell my app when that method is called it doesn't need to connect to the database as there is no ActiveRecord query calls in it? 无论如何告诉我的应用程序何时调用该方法它不需要连接到数据库,因为它没有ActiveRecord查询调用?
One possible way to do this is to use middleware. 一种可能的方法是使用中间件。 A good resource for setting up your own middleware is http://railscasts.com/episodes/151-rack-middleware?view=asciicast
设置自己的中间件的一个很好的资源是http://railscasts.com/episodes/151-rack-middleware?view=asciicast
However, I'm not convinced that the problem you're experiencing is because of too many connections to Postgres. 但是,我不相信你遇到的问题是因为与Postgres的连接太多了。 This is just a hunch, but I think your problem may lie elsewhere.
这只是一种预感,但我认为你的问题可能在其他地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.