-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set statement timeout by default (#106)
* Set statement timeout by default * Style * Isolate statement insurer in its helper * Post rebase * review
- Loading branch information
Thomas Hareau
committed
Jul 6, 2023
1 parent
726cec4
commit 69a637a
Showing
16 changed files
with
113 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/safe-pg-migrations/helpers/session_setting_management.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module SafePgMigrations | ||
module Helpers | ||
module SessionSettingManagement | ||
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 | ||
|
||
def without_statement_timeout(&block) | ||
with_setting(:statement_timeout, 0, &block) | ||
end | ||
|
||
def without_lock_timeout(&block) | ||
with_setting(:lock_timeout, 0, &block) | ||
end | ||
|
||
def without_timeout(&block) | ||
without_statement_timeout { without_lock_timeout(&block) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.