module Cutoff::Patch::Mysql2
Sets the max execution time for SELECT queries if there is an active cutoff and it has time remaining. You can select this patch with `exclude` or `only` using the checkpoint name `:mysql2`.
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 21 def query(sql, options = {}) cutoff = Cutoff.current return super unless cutoff&.selected?(:mysql2) cutoff.checkpoint!(:mysql2) sql = QueryWithMaxTime.new(sql, cutoff.ms_remaining.ceil).to_s super end