digital-fabric / extralite

Ruby on SQLite

Home Page:http://www.rubydoc.info/gems/extralite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set busy_timeout using the sequel adapter

lazaronixon opened this issue · comments

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.

# db.busy_timeout(typecast_value_integer(opts.fetch(:timeout, 5000)))

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

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