0

I am quite new at Ruby/Rails. I am building a service that make an API available to users and ends up with some files created in the local filesystem, without any need to connect to any database. Then, once every few hours, I want to run a piece of ruby code that takes these local files, uploads them to Amazon S3 and registers their location into a Postgres database.

Right now both codes live together in the same project. I am observing that every time a user does something the system connects to the database. I have seen this answer which recommends to eliminate all traces of ActiveRecord in my code, but given that I want to have my background bookkeeping process connect to the database I am stuck on what to do.

Is it possible to define two different profiles (one with database and one without) and specify which profile a certain function call should run on? would this work?

3
  • Are you sure there is any problem if you connect to the database when the application starts and not when you run the background job? Commented Feb 19, 2016 at 18:57
  • In my understanding of Postgres databases (actually, of those that are offered by Amazon and others) I have a maximum number of connections I can make at once. I am trying to use a modest database and I believe my server is blocking when I reach this maximum. For this reason I would like to avoid connecting at all, as I do not really need it. Commented Feb 19, 2016 at 19:24
  • More queries you execute more you program get slow, try limiting the number of queries. Commented Feb 19, 2016 at 23:54

1 Answer 1

1

I'm a bit confused by this, the db does not magically connect to the database for kicks on every request, it does so because of a specific request requires it. Generally through ActiveRecord but not exclusively

If your system is connecting every time you make a request, then that implies you have some sort of user metric or authorisation based code in there. Just killing off the database will cause this to fail, and likely you'll have to find it anyways, to then get your system to work. I'd advise locating it.

Things to look for are before_filters in controllers, or database session management, for example, or look for what is in the logs - the query should appear - and that will tell you what is being loaded, modified or whatnot.

It might even work to stop your database, just before doing a user activity, and see where the error leads you. Rinse and repeat until the user activity works, without the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.