How do I set the ActiveRecord query timeout for mysql?

后端 未结 2 2072
刺人心
刺人心 2020-12-19 11:17

How can I set the mysql query timeout in ActiveRecord? I wish to set it to something very short, like 10-15ms. This is for a Sinatra ruby web app.

Thanks.

2条回答
  •  清歌不尽
    2020-12-19 11:47

    You could also set it in a per-connection basis like this:

    ActiveRecord::Base.connection.instance_variable_get('@connection').instance_variable_set('@read_timeout', 0)
    

    I'm doing this for instance to have a default read_timeout, but override it for my long-running nightly scripts.

提交回复
热议问题