pgmq-ruby 0.9.0 → 0.10.0
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/CHANGELOG.md +16 -0
- data/README.md +29 -14
- data/lib/pgmq/client.rb +10 -9
- data/lib/pgmq/connection.rb +12 -8
- data/lib/pgmq/contractable/result.rb +1 -1
- data/lib/pgmq/version.rb +1 -1
- data/lib/pgmq.rb +2 -2
- 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: f22badf745600819d32d04a0af17955b3517a40bdb9b0a4c9a553e642d84747e
|
|
4
|
+
data.tar.gz: 6c82b75ec212a69f2aee957a03879ddd8dd448b3716d2e2a5cf747b9a014666e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0b1e5e2a8a37fa92f03d0b92749390a39750e9477fc71217b4c92e2ce3930d2853719c210c2318013dea4df884f5648961a025f9a399a13cfe278c43ad89858
|
|
7
|
+
data.tar.gz: b201e1c734639cd358cb77c23e494bc761f49699ac34c2ec9685e52da55b1396b1e8698935f989360a65674f961e2d3f11aabcc77caaccb804e709f9cec0092b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
### Infrastructure
|
|
6
|
+
- **[Fix]** The release job installs its gems into `vendor/bundle` instead of the Ruby install, so json 3.x from `Gemfile.lock` does not reach `sigstore-cli 0.2.3` (run outside the bundle by `rubygems/release-gem`), which crashed with it and made the gem go out without a Sigstore attestation. `rubygems/release-gem` is bumped to v1.4.2, which fixes the release wait that failed the job under Ruby 4.0.
|
|
7
|
+
- **[Change]** Drop PostgreSQL 14 from CI and the README requirements: PGMQ v1.13.2 supports PostgreSQL 15-18 and no longer rebuilds the `pg14-pgmq` image. PostgreSQL 14 reached end of life on 2026-11-12.
|
|
8
|
+
|
|
9
|
+
### Documentation
|
|
10
|
+
- **[Fix]** The `with_connection` docs said a block that loses its connection still raises
|
|
11
|
+
`PGMQ::Errors::ConnectionError` (README, 0.9.0 entry) and that the retry happens only before any SQL is sent (YARD of
|
|
12
|
+
`PGMQ::Client#with_connection`). With `auto_reconnect: true` (the default), a lost-connection error makes the whole
|
|
13
|
+
block run once more, also after it sent SQL, and a retry that succeeds raises nothing. The README and YARD now say so
|
|
14
|
+
and ask for a block that is safe to run twice, or `auto_reconnect: false`.
|
|
15
|
+
- **[Fix]** The README and YARD connection-hash examples passed the hash without braces, so `PGMQ::Client.new` and
|
|
16
|
+
`PGMQ::Connection.new` raised `ArgumentError`. They now wrap the hash in braces. The YARD auto-reconnect example
|
|
17
|
+
passed no connection parameters and raised `PGMQ::Errors::ConfigurationError`; it now passes a connection string.
|
|
18
|
+
|
|
3
19
|
## 0.9.0 (2026-11-10)
|
|
4
20
|
|
|
5
21
|
### Producer
|
data/README.md
CHANGED
|
@@ -97,7 +97,8 @@ This gem provides complete support for all core PGMQ SQL functions. Based on the
|
|
|
97
97
|
## Requirements
|
|
98
98
|
|
|
99
99
|
- Ruby 3.3+
|
|
100
|
-
- PostgreSQL
|
|
100
|
+
- PostgreSQL 15-18 with PGMQ extension installed
|
|
101
|
+
- PGMQ v1.13.1 or newer recommended: earlier versions have a high-severity privilege escalation ([GHSA-mwqf-p4r3-798v](https://github.com/pgmq/pgmq/security/advisories/GHSA-mwqf-p4r3-798v))
|
|
101
102
|
|
|
102
103
|
### Installing PGMQ Extension
|
|
103
104
|
|
|
@@ -182,13 +183,13 @@ gem install pgmq-ruby
|
|
|
182
183
|
require 'pgmq'
|
|
183
184
|
|
|
184
185
|
# Connect to database
|
|
185
|
-
client = PGMQ::Client.new(
|
|
186
|
+
client = PGMQ::Client.new({
|
|
186
187
|
host: 'localhost',
|
|
187
188
|
port: 5432,
|
|
188
189
|
dbname: 'mydb',
|
|
189
190
|
user: 'postgres',
|
|
190
191
|
password: 'secret'
|
|
191
|
-
)
|
|
192
|
+
})
|
|
192
193
|
|
|
193
194
|
# Create a queue
|
|
194
195
|
client.create('orders')
|
|
@@ -245,16 +246,21 @@ PGMQ-Ruby supports multiple ways to connect:
|
|
|
245
246
|
|
|
246
247
|
```ruby
|
|
247
248
|
client = PGMQ::Client.new(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
{
|
|
250
|
+
host: 'localhost',
|
|
251
|
+
port: 5432,
|
|
252
|
+
dbname: 'mydb',
|
|
253
|
+
user: 'postgres',
|
|
254
|
+
password: 'secret'
|
|
255
|
+
},
|
|
253
256
|
pool_size: 5, # Default: 5
|
|
254
257
|
pool_timeout: 5 # Default: 5 seconds
|
|
255
258
|
)
|
|
256
259
|
```
|
|
257
260
|
|
|
261
|
+
Wrap the connection hash in braces. Without them, Ruby passes `host:`, `port:` and the other keys as keyword
|
|
262
|
+
arguments, and `PGMQ::Client.new` raises `ArgumentError` (unknown keywords).
|
|
263
|
+
|
|
258
264
|
### Connection String
|
|
259
265
|
|
|
260
266
|
```ruby
|
|
@@ -309,7 +315,17 @@ without standing up a second connection pool. The connection is health-checked
|
|
|
309
315
|
(when `auto_reconnect` is enabled) and returned to the pool when the block exits.
|
|
310
316
|
If the block raises `PG::ConnectionBad` or `PG::UnableToSend`, the connection is
|
|
311
317
|
reset before it goes back to the pool (connections from a callable are left as
|
|
312
|
-
they are)
|
|
318
|
+
they are).
|
|
319
|
+
|
|
320
|
+
With `auto_reconnect: true` (the default), a lost-connection error (see
|
|
321
|
+
[Extending the lost-connection error matchers](#extending-the-lost-connection-error-matchers))
|
|
322
|
+
makes `with_connection` run the **whole block** once more, on whichever
|
|
323
|
+
connection the pool hands out next. If that run succeeds, the call returns
|
|
324
|
+
normally and you see no error. You get `PGMQ::Errors::ConnectionError` only
|
|
325
|
+
when the second run fails too, or right away with `auto_reconnect: false`.
|
|
326
|
+
Statements that ran before the connection was lost (e.g. a `pg_notify`) can
|
|
327
|
+
therefore run twice: keep the block safe to run twice, or disable
|
|
328
|
+
`auto_reconnect`.
|
|
313
329
|
|
|
314
330
|
```ruby
|
|
315
331
|
# Fire a custom NOTIFY alongside your queues
|
|
@@ -368,11 +384,10 @@ pattern) raise `PGMQ::Errors::ConfigurationError` immediately so
|
|
|
368
384
|
misconfiguration can't silently disable retries.
|
|
369
385
|
|
|
370
386
|
> **Reserve these options for connection-level failures.** A "reconnectable"
|
|
371
|
-
> error
|
|
372
|
-
>
|
|
373
|
-
>
|
|
374
|
-
>
|
|
375
|
-
> mask bugs.
|
|
387
|
+
> error should mean the socket is dead. Do **not** add patterns or classes for
|
|
388
|
+
> query-level errors (deadlocks, constraint violations, statement timeouts) -
|
|
389
|
+
> those will replay your operation against a healthy connection and may cause
|
|
390
|
+
> duplicate work or mask bugs.
|
|
376
391
|
|
|
377
392
|
**Connection Pool Benefits:**
|
|
378
393
|
- **Thread-safe** - Multiple threads can safely share a single client
|
data/lib/pgmq/client.rb
CHANGED
|
@@ -7,12 +7,12 @@ module PGMQ
|
|
|
7
7
|
# integration), use pgmq-framework.
|
|
8
8
|
#
|
|
9
9
|
# @example Basic usage
|
|
10
|
-
# client = PGMQ::Client.new(
|
|
10
|
+
# client = PGMQ::Client.new({
|
|
11
11
|
# host: 'localhost',
|
|
12
12
|
# dbname: 'mydb',
|
|
13
13
|
# user: 'postgres',
|
|
14
14
|
# password: 'postgres'
|
|
15
|
-
# )
|
|
15
|
+
# })
|
|
16
16
|
# client.create('my_queue')
|
|
17
17
|
# msg_id = client.produce('my_queue', '{"data":"value"}')
|
|
18
18
|
# msg = client.read('my_queue', vt: 30)
|
|
@@ -64,13 +64,13 @@ module PGMQ
|
|
|
64
64
|
# client = PGMQ::Client.new('postgres://user:pass@localhost/db')
|
|
65
65
|
#
|
|
66
66
|
# @example Connection hash
|
|
67
|
-
# client = PGMQ::Client.new(host: 'localhost', dbname: 'mydb', user: 'postgres')
|
|
67
|
+
# client = PGMQ::Client.new({ host: 'localhost', dbname: 'mydb', user: 'postgres' })
|
|
68
68
|
#
|
|
69
69
|
# @example Inject existing connection (for Rails)
|
|
70
70
|
# client = PGMQ::Client.new(-> { ActiveRecord::Base.connection.raw_connection })
|
|
71
71
|
#
|
|
72
72
|
# @example Disable auto-reconnect
|
|
73
|
-
# client = PGMQ::Client.new(auto_reconnect: false)
|
|
73
|
+
# client = PGMQ::Client.new('postgres://user:pass@localhost/db', auto_reconnect: false)
|
|
74
74
|
def initialize(
|
|
75
75
|
conn_params = nil,
|
|
76
76
|
pool_size: Connection::DEFAULT_POOL_SIZE,
|
|
@@ -118,9 +118,10 @@ module PGMQ
|
|
|
118
118
|
# Checks out a pooled connection and yields the raw +PG::Connection+ for arbitrary SQL.
|
|
119
119
|
#
|
|
120
120
|
# All PGMQ operations run through this method internally, so it carries the same guarantees: a connection is taken
|
|
121
|
-
# from the pool, health-checked when +auto_reconnect+ is enabled, and
|
|
122
|
-
#
|
|
123
|
-
#
|
|
121
|
+
# from the pool, health-checked when +auto_reconnect+ is enabled, and returned to the pool when the block exits.
|
|
122
|
+
# With +auto_reconnect+ (the default), a lost-connection error makes the whole block run once more, on whichever
|
|
123
|
+
# connection the pool hands out next, also when the block already sent SQL: keep the block safe to run twice (see
|
|
124
|
+
# {PGMQ::Connection#with_connection}).
|
|
124
125
|
#
|
|
125
126
|
# Exposed so callers can issue PostgreSQL statements PGMQ does not wrap without standing up a second pool: ad-hoc
|
|
126
127
|
# +NOTIFY+, +LISTEN+, advisory locks, custom monitoring queries, or DDL that lives alongside your queue tables.
|
|
@@ -128,8 +129,8 @@ module PGMQ
|
|
|
128
129
|
#
|
|
129
130
|
# @yield [PG::Connection] a pooled, health-checked database connection
|
|
130
131
|
# @return [Object] the return value of the block
|
|
131
|
-
# @raise [PGMQ::Errors::ConnectionError] if the block raises any `PG::Error` (the original is in `#cause`)
|
|
132
|
-
# connection cannot be obtained
|
|
132
|
+
# @raise [PGMQ::Errors::ConnectionError] if the block raises any `PG::Error` (the original is in `#cause`) and it is
|
|
133
|
+
# not retried or the retry fails too, or a connection cannot be obtained
|
|
133
134
|
#
|
|
134
135
|
# @example Fire a custom NOTIFY on the PGMQ pool
|
|
135
136
|
# client.with_connection do |conn|
|
data/lib/pgmq/connection.rb
CHANGED
|
@@ -15,7 +15,7 @@ module PGMQ
|
|
|
15
15
|
# conn = PGMQ::Connection.new("postgres://localhost/mydb")
|
|
16
16
|
#
|
|
17
17
|
# @example With connection hash
|
|
18
|
-
# conn = PGMQ::Connection.new(host: 'localhost', dbname: 'mydb')
|
|
18
|
+
# conn = PGMQ::Connection.new({ host: 'localhost', dbname: 'mydb' })
|
|
19
19
|
#
|
|
20
20
|
# @example With Rails ActiveRecord (reuses Rails connection pool)
|
|
21
21
|
# conn = PGMQ::Connection.new(-> { ActiveRecord::Base.connection.raw_connection })
|
|
@@ -32,9 +32,10 @@ module PGMQ
|
|
|
32
32
|
private_constant :CONTRACT
|
|
33
33
|
|
|
34
34
|
class << self
|
|
35
|
-
# Additional error message patterns (String or Regexp) that mean the connection is dead
|
|
36
|
-
#
|
|
37
|
-
# built-in LOST_CONNECTION_MESSAGES are always checked first -
|
|
35
|
+
# Additional error message patterns (String or Regexp) that mean the connection is dead. With +auto_reconnect+, a
|
|
36
|
+
# match makes {PGMQ::Connection#with_connection} run its block once more. Strings are matched as case-insensitive
|
|
37
|
+
# substrings; Regexps match the original message. The built-in LOST_CONNECTION_MESSAGES are always checked first -
|
|
38
|
+
# this list is appended to them.
|
|
38
39
|
#
|
|
39
40
|
# Thread-safe: reads are lock-free (frozen array swap); writes should be done at boot time before forking workers.
|
|
40
41
|
#
|
|
@@ -127,10 +128,14 @@ module PGMQ
|
|
|
127
128
|
# When the block raises `PG::ConnectionBad` or `PG::UnableToSend`, the connection is reset before it goes back to
|
|
128
129
|
# the pool, so the next checkout gets a working one. Connections from a callable are left as they are.
|
|
129
130
|
#
|
|
131
|
+
# With `auto_reconnect`, a lost-connection error (see {#connection_lost_error?}) raised by the health check or the
|
|
132
|
+
# block makes the whole block run once more, on whichever connection the pool hands out next. Statements the first
|
|
133
|
+
# run already sent can run twice. A retry that succeeds returns normally.
|
|
134
|
+
#
|
|
130
135
|
# @yield [PG::Connection] database connection
|
|
131
136
|
# @return [Object] result of the block
|
|
132
|
-
# @raise [PGMQ::Errors::ConnectionError] if the block raises any `PG::Error` (the original is in `#cause`)
|
|
133
|
-
# connection cannot be obtained
|
|
137
|
+
# @raise [PGMQ::Errors::ConnectionError] if the block raises any `PG::Error` (the original is in `#cause`) and it is
|
|
138
|
+
# not retried or the retry fails too, or a connection cannot be obtained
|
|
134
139
|
def with_connection
|
|
135
140
|
retries = @auto_reconnect ? 1 : 0
|
|
136
141
|
attempts = 0
|
|
@@ -232,8 +237,7 @@ module PGMQ
|
|
|
232
237
|
# patterns (strings matched as case-insensitive substrings, Regexps matched against the original message).
|
|
233
238
|
#
|
|
234
239
|
# @param error [PG::Error] the error to check
|
|
235
|
-
# @return [Boolean] true if the connection was lost and a retry
|
|
236
|
-
# fresh connection is appropriate
|
|
240
|
+
# @return [Boolean] true if the connection was lost and a retry is appropriate
|
|
237
241
|
def connection_lost_error?(error)
|
|
238
242
|
return true if LOST_CONNECTION_ERRORS.any? { |klass| error.is_a?(klass) }
|
|
239
243
|
|
|
@@ -34,7 +34,7 @@ module PGMQ
|
|
|
34
34
|
hashed = {}
|
|
35
35
|
|
|
36
36
|
errors.each do |error|
|
|
37
|
-
scope = error.first.
|
|
37
|
+
scope = error.first.join(".").to_sym
|
|
38
38
|
|
|
39
39
|
# This will allow for usage of custom messages instead of yaml keys if needed
|
|
40
40
|
hashed[scope] = if error.last.is_a?(String)
|
data/lib/pgmq/version.rb
CHANGED
data/lib/pgmq.rb
CHANGED
|
@@ -19,13 +19,13 @@ loader.setup
|
|
|
19
19
|
# require 'pgmq'
|
|
20
20
|
#
|
|
21
21
|
# # Create client with connection parameters
|
|
22
|
-
# client = PGMQ::Client.new(
|
|
22
|
+
# client = PGMQ::Client.new({
|
|
23
23
|
# host: 'localhost',
|
|
24
24
|
# port: 5432,
|
|
25
25
|
# dbname: 'mydb',
|
|
26
26
|
# user: 'postgres',
|
|
27
27
|
# password: 'postgres'
|
|
28
|
-
# )
|
|
28
|
+
# })
|
|
29
29
|
#
|
|
30
30
|
# # Or with connection string
|
|
31
31
|
# client = PGMQ::Client.new('postgres://localhost/mydb')
|