Home > Software engineering >  heroku rails console query kicks out if too complex
heroku rails console query kicks out if too complex

Time:11-29

I am trying to run a fairly complex query on our production database which is hosted on heroku. These are generally one-off fact finding queries but I am being kicked out each time I try to run it. Locally, the query runs fine and is fairly quick. It's also worse if I assign the result to a variable.

Any help regarding extending the time before heroku kicks me out or other ways to query the database would be greatly appreciated.

FYI - query I was running

authors = Author.includes(:books).where(books: {book_release_date: ('01/01/2020'.to_date.beginning_of_day..'30/12/2022'.to_date.end_of_day)})

The console closes without error which is deeply unhelpful. I am running this from the Heroku CLI i.e. heroku run rails console.

CodePudding user response:

I think you should extract the year in sql for your case. Something like that should be much more efficient:

Author.includes(:books).where("extract(year  from books.book_release_date) = ?", 2020)

CodePudding user response:

The console closes without error which is deeply unhelpful. I am running this from the Heroku CLI i.e. heroku run rails console.

This spins up a one-off dyno, and one-off dynos time out after an hour of inactivity:

Connections to one-off dynos will be closed after one hour of inactivity (in both input and output). When the connection is closed, the dyno will be sent SIGHUP. This idle timeout helps prevent unintended charges from leaving interactive console sessions open and unused.

You should be able to use nohup to disable this behaviour, e.g. by running

heroku run nohup rails console

Or, just interact with the console at least once per hour, e.g. by hitting enter.

  • Related