digital-fabric / extralite

Ruby on SQLite
http://www.rubydoc.info/gems/extralite
MIT License
247 stars 7 forks source link

Set busy_timeout using the sequel adapter #70

Closed lazaronixon closed 4 months ago

lazaronixon commented 4 months ago

I'm having many Extralite::BusyError, how to set busy_timeout or even better, implement a busy_handler with a retry policy? I'm using the sequel adapter and the property busy_timeout is not available.

https://github.com/digital-fabric/extralite/blob/33d3e754233a53675e4b952a49184b5f8a37a216/lib/sequel/adapters/extralite.rb#L123

With sqlite3 I could do something like this:

after_connect = proc do |db|
  db.busy_handler do |count|
    (count <= 100).tap { |result| sleep count * 0.001 if result }
  end
end

require "sequel/core"
DB = Sequel.connect(database_url, logger: LOGGER, after_connect: after_connect)
DB.transaction_mode = :immediate
lazaronixon commented 4 months ago

Fixed =)

require "logger"
LOGGER = Logger.new($stdout)
LOGGER.level = ENV.fetch("RODA_LOG_LEVEL", "info")

database_url = ENV.fetch("DATABASE_URL") { "extralite://storage/development.sqlite" }

after_connect = proc do |db|
  db.busy_timeout = 5
end

require "sequel/core"
DB = Sequel.connect(database_url, logger: LOGGER, after_connect: after_connect)
DB.transaction_mode = :immediate