Module: SafePgMigrations::Helpers::SessionSettingManagement
- Included in:
- StatementInsurer
- Defined in:
- lib/safe-pg-migrations/helpers/session_setting_management.rb
Instance Method Summary collapse
- #with_setting(key, value) ⇒ Object
- #without_lock_timeout(&block) ⇒ Object
- #without_statement_timeout(&block) ⇒ Object
- #without_timeout(&block) ⇒ Object
Instance Method Details
#with_setting(key, value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/safe-pg-migrations/helpers/session_setting_management.rb', line 6 def with_setting(key, value) old_value = query_value("SHOW #{key}") execute("SET #{key} TO #{quote(value)}") begin yield ensure begin execute("SET #{key} TO #{quote(old_value)}") rescue ActiveRecord::StatementInvalid => e # Swallow `PG::InFailedSqlTransaction` exceptions so as to keep the # original exception (if any). raise unless e.cause.is_a?(PG::InFailedSqlTransaction) end end end |
#without_lock_timeout(&block) ⇒ Object
26 27 28 |
# File 'lib/safe-pg-migrations/helpers/session_setting_management.rb', line 26 def without_lock_timeout(&block) with_setting(:lock_timeout, 0, &block) end |
#without_statement_timeout(&block) ⇒ Object
22 23 24 |
# File 'lib/safe-pg-migrations/helpers/session_setting_management.rb', line 22 def without_statement_timeout(&block) with_setting(:statement_timeout, 0, &block) end |
#without_timeout(&block) ⇒ Object
30 31 32 |
# File 'lib/safe-pg-migrations/helpers/session_setting_management.rb', line 30 def without_timeout(&block) without_statement_timeout { without_lock_timeout(&block) } end |