Module: Cutoff::Patch::Mysql2

Defined in:
lib/cutoff/patch/mysql2.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#query(sql, options = {}) ⇒ Object

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

Raises:

  • CutoffExceededError If the cutoff is exceeded. The query will not be executed in this case.

See Also:

  • Mysql2::Client#query


21
22
23
24
25
26
27
28
# 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