pgtk 0.30.9 → 0.30.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pgtk/retry.rb +13 -10
- data/lib/pgtk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eef46168e2daa0ddc6721aac48a99dc20f8aa80f078cfc76a31fa4ec70759af6
|
|
4
|
+
data.tar.gz: 13dc7a6f18fcb34385c3580700e8e192b3bb38daab86f64b85fa64ac3f3dcce0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18489070b6f37d64338982c7ade356881ffe7a6fc01f6cc1b837f2433ed2779a4838388ec60468ec80c3a21342b7f9c19b52bb87792c7bf0dc7011fb7163d9cd
|
|
7
|
+
data.tar.gz: bc115bdd5e53ff555e1e1d383d90f9ecc80d33b282cd57e89b03540a14f35792e718b5f74c64a637c761da7762791edcc9534f49612ebe5984836817c1e1c314
|
data/lib/pgtk/retry.rb
CHANGED
|
@@ -49,11 +49,17 @@ require_relative 'impatient'
|
|
|
49
49
|
# Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
50
50
|
# License:: MIT
|
|
51
51
|
class Pgtk::Retry
|
|
52
|
+
# Raised when all retry attempts have been exhausted. The original
|
|
53
|
+
# exception that caused the last failure is available via #cause,
|
|
54
|
+
# so its message and stack trace are preserved for debugging.
|
|
55
|
+
class Exhausted < StandardError; end
|
|
56
|
+
|
|
52
57
|
# Constructor.
|
|
53
58
|
#
|
|
54
59
|
# @param [Pgtk::Pool] pool The pool to decorate
|
|
55
60
|
# @param [Integer] attempts Number of attempts to make (default: 3)
|
|
56
61
|
def initialize(pool, attempts: 3)
|
|
62
|
+
raise(ArgumentError, "Attempts must be at least 2, while #{attempts} provided") if attempts < 2
|
|
57
63
|
@pool = pool
|
|
58
64
|
@attempts = attempts
|
|
59
65
|
end
|
|
@@ -79,10 +85,11 @@ class Pgtk::Retry
|
|
|
79
85
|
].join("\n")
|
|
80
86
|
end
|
|
81
87
|
|
|
82
|
-
# Execute a SQL query with automatic retry for SELECT queries.
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
88
|
+
# Execute a SQL query with automatic retry for SELECT queries only.
|
|
89
|
+
# Non-SELECT queries fail on the first error, since a failure may occur
|
|
90
|
+
# after the server received the query but before the acknowledgement
|
|
91
|
+
# reached the client, and retrying a non-idempotent write could duplicate
|
|
92
|
+
# it.
|
|
86
93
|
#
|
|
87
94
|
# @param [String] sql The SQL query with params inside (possibly)
|
|
88
95
|
# @return [Array] Result rows
|
|
@@ -91,14 +98,10 @@ class Pgtk::Retry
|
|
|
91
98
|
attempt = 0
|
|
92
99
|
begin
|
|
93
100
|
@pool.exec(sql, *)
|
|
94
|
-
rescue
|
|
95
|
-
attempt += 1
|
|
96
|
-
raise(e) if attempt >= @attempts
|
|
97
|
-
retry
|
|
98
|
-
rescue StandardError => e
|
|
101
|
+
rescue StandardError, Pgtk::Impatient::TooSlow => e
|
|
99
102
|
raise(e) unless query.strip.upcase.start_with?('SELECT')
|
|
100
103
|
attempt += 1
|
|
101
|
-
raise(e) if attempt >= @attempts
|
|
104
|
+
raise(Exhausted, "Retry gave up after #{@attempts} attempts: #{e.message}") if attempt >= @attempts
|
|
102
105
|
retry
|
|
103
106
|
end
|
|
104
107
|
end
|
data/lib/pgtk/version.rb
CHANGED