module Cutoff::Patch::Mysql2

Sets the max execution time for SELECT queries if there is an active cutoff and it has time remaining

Public Instance Methods

query(sql, options = {}) click to toggle source

Overrides `Mysql2::Client#query` to insert a MAX_EXECUTION_TIME query hint with the remaining cutoff time

If the cutoff is already exceeded, the query will not be executed and a {CutoffExceededError} will be raised

@see Mysql2::Client#query @raise CutoffExceededError If the cutoff is exceeded. The query will not

be executed in this case.
Calls superclass method
# File lib/cutoff/patch/mysql2.rb, line 20
def query(sql, options = {})
  cutoff = Cutoff.current
  return super unless cutoff

  cutoff.checkpoint!
  sql = QueryWithMaxTime.new(sql, cutoff.ms_remaining.ceil).to_s
  super
end