【问题标题】:Is it possible to set a statement_timeout for the db for *only* web queries in Rails?是否可以在 Rails 中为 db 设置 *only* Web 查询的 statement_timeout?
【发布时间】:2019-10-20 06:35:41
【问题描述】:

是否可以为 Ruby on Rails(与 sidekiq 工作人员/作业)中的 only Web 查询设置 db (Postgres) 的 statement_timeout?原因是 Heroku 网络查询在 30 秒后超时,因此在此之后终止来自 Puma 的查询是有意义的。但我希望 sidekiq db 查询能够执行更长时间?

我已经尝试在 database.yml 中做类似的事情

  primary:
    <<: *default
    url: <%= ENV['DATABASE_URL']) %>
    variables:
      statement_timeout: <%= ENV["STATEMENT_TIMEOUT"] || "0" %>

然后在我的Procfile 中执行此操作

web: STATEMENT_TIMEOUT=30s bundle exec puma

但它没有用。几个请求后,语句超时将重置回 0。

【问题讨论】:

  • 你使用的是哪个 ORM?
  • 使用 ActiveRecord

标签: ruby-on-rails heroku heroku-postgres


【解决方案1】:

这可能是语法问题;我用ms写了我的,效果很好。

web: STATEMENT_TIMEOUT=30000 bundle exec puma

我翻转它以为我的工人提供覆盖,然后默认为 27 秒,否则:

# database.yml
<% statement_timeout = ENV['STATEMENT_TIMEOUT'] || '27000' %>

production:
  ...
  variables:
    statement_timeout: <%= statement_timeout %>

在我的Procfile:

web: bundle exec puma -C config/puma.rb
worker: STATEMENT_TIMEOUT=600000 rake jobs:work

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 2018-10-23
    • 2011-03-06
    • 2013-11-19
    • 2021-12-03
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多