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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pgtk/retry.rb +13 -10
  3. data/lib/pgtk/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e73feebd4e15e2cd5ed8a862dd3f739e417cb2b24967efb084be032ceb4ea0a
4
- data.tar.gz: 6e992abff2e960da1cf93b9bbac4c4f09a72482b65ce2e60e89e8597bb40bc20
3
+ metadata.gz: eef46168e2daa0ddc6721aac48a99dc20f8aa80f078cfc76a31fa4ec70759af6
4
+ data.tar.gz: 13dc7a6f18fcb34385c3580700e8e192b3bb38daab86f64b85fa64ac3f3dcce0
5
5
  SHA512:
6
- metadata.gz: 9279442627e304c9489fba9ad8a2b3bef33fa4ec5602656cd2955f683087338f171593cc4d686a1b5b79d105bb4bb0000a99ea5176c0e64c61b709d97b400e64
7
- data.tar.gz: f94ac7b9215ca461f2b9fc1692c2ba9ca5a1ad7ebc06363480812b01cc7b91a425d945f28f6f36ee52dd774f07ea016778469e3243afefba1c379f749f1a6645
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
- # Also retries PG::ConnectionBad and Pgtk::Impatient::TooSlow errors
84
- # for all query types, since they indicate the query never completed
85
- # against PostgreSQL and can be safely re-issued.
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 PG::ConnectionBad, Pgtk::Impatient::TooSlow => e
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
@@ -10,5 +10,5 @@ require_relative '../pgtk'
10
10
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
11
11
  # License:: MIT
12
12
  module Pgtk
13
- VERSION = '0.30.9' unless defined?(VERSION)
13
+ VERSION = '0.30.10' unless defined?(VERSION)
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.9
4
+ version: 0.30.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko