Is it possible to set a statement_timeout for the db (Postgres) for only web queries in Ruby on Rails (vs sidekiq workers/jobs)? Reason being Heroku web queries timeout after 30 seconds so it makes sense to kill queries from Puma after that. But I want sidekiq db queries to be able to execute for much longer?
I already tried doing something like this in database.yml
primary:
<<: *default
url: <%= ENV['DATABASE_URL']) %>
variables:
statement_timeout: <%= ENV["STATEMENT_TIMEOUT"] || "0" %>
Then doing this in my Procfile
web: STATEMENT_TIMEOUT=30s bundle exec puma
But it didn't work. The statement timeout would get reset back to 0 after a few requests.
It might've been a syntax issue; I wrote mine out in ms and it works fine.
web: STATEMENT_TIMEOUT=30000 bundle exec puma
I flipped it to provide an override for my workers, and then defaulted to 27 sec otherwise:
# database.yml
<% statement_timeout = ENV['STATEMENT_TIMEOUT'] || '27000' %>
production:
...
variables:
statement_timeout: <%= statement_timeout %>
and in my Procfile
:
web: bundle exec puma -C config/puma.rb
worker: STATEMENT_TIMEOUT=600000 rake jobs:work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With