Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel Rails DB connection

I am writing an app that uses Server Side events with ActionController::Live. It is using the puma app server. A method in the Messages controller stays alive while the user is connected waiting for messages from Redis.

The problem is that I don't want to connect to Postgres on this method. 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.

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?

like image 816
roryhughes Avatar asked Jun 17 '13 16:06

roryhughes


1 Answers

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

However, I'm not convinced that the problem you're experiencing is because of too many connections to Postgres. This is just a hunch, but I think your problem may lie elsewhere.

like image 100
adriandz Avatar answered Sep 30 '22 04:09

adriandz