pgbus 0.21.2 → 0.21.4

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.
@@ -16,6 +16,23 @@ module Pgbus
16
16
  SCHEMA_DIR = File.expand_path("pgmq_schema", __dir__).freeze
17
17
  FIXUPS_DIR = File.join(SCHEMA_DIR, "fixups").freeze
18
18
 
19
+ # Wrapped around the vendored SQL by install_sql; see there.
20
+ SAVE_SEARCH_PATH_SQL = <<~SQL
21
+ DO $pgbus_save_path$
22
+ BEGIN
23
+ PERFORM pg_catalog.set_config('pgbus.install_saved_search_path', pg_catalog.current_setting('search_path'), true);
24
+ END
25
+ $pgbus_save_path$;
26
+ SQL
27
+
28
+ RESTORE_SEARCH_PATH_SQL = <<~SQL
29
+ DO $pgbus_restore_path$
30
+ BEGIN
31
+ PERFORM pg_catalog.set_config('search_path', pg_catalog.current_setting('pgbus.install_saved_search_path'), true);
32
+ END
33
+ $pgbus_restore_path$;
34
+ SQL
35
+
19
36
  class << self
20
37
  # Returns the latest vendored PGMQ version string.
21
38
  def latest_version
@@ -78,11 +95,21 @@ module Pgbus
78
95
  # Strips the extension-only pg_dump config blocks since they're
79
96
  # irrelevant when not installed as an extension.
80
97
  #
98
+ # From 1.13.1 upstream pins `search_path = pg_catalog, pg_temp` for the
99
+ # install with a transaction-local set_config, which outlives the install
100
+ # inside a migration (or a caller's transaction, in the client's lazy
101
+ # install): the next unqualified CREATE TABLE would target pg_catalog.
102
+ # The caller's path is saved before upstream's text and restored after,
103
+ # both transaction-local, so the install's pinning still applies to its
104
+ # own statements and nothing after them. Run the result as one string:
105
+ # a statement-by-statement load would lose the saved path between
106
+ # statements.
107
+ #
81
108
  # @param version [String] defaults to latest
82
109
  # @return [String] SQL
83
110
  def install_sql(version = latest_version)
84
- sql = sql_for_version(version)
85
- strip_extension_only_blocks(sql)
111
+ sql = strip_extension_only_blocks(sql_for_version(version))
112
+ "#{SAVE_SEARCH_PATH_SQL}\n#{sql}\n#{RESTORE_SEARCH_PATH_SQL}"
86
113
  end
87
114
 
88
115
  # Returns SQL to create the version tracking table and record an installation.
@@ -231,9 +258,12 @@ module Pgbus
231
258
  ""
232
259
  )
233
260
 
234
- # Remove _belongs_to_pgmq function (checks pg_depend on extension)
261
+ # Remove _belongs_to_pgmq function (checks pg_depend on extension).
262
+ # From 1.13.1 its terminator carries `SET search_path = ...`; ending
263
+ # the match at a bare `LANGUAGE plpgsql;` would run on to the next
264
+ # function without that clause and strip everything in between.
235
265
  sql.gsub(
236
- /CREATE FUNCTION pgmq\._belongs_to_pgmq.*?LANGUAGE plpgsql;/m,
266
+ /CREATE FUNCTION pgmq\._belongs_to_pgmq.*?\$\$\s*LANGUAGE plpgsql[^;]*;/m,
237
267
  ""
238
268
  )
239
269
  end
data/lib/pgbus/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- VERSION = "0.21.2"
4
+ VERSION = "0.21.4"
5
5
  end
@@ -1340,7 +1340,8 @@ module Pgbus
1340
1340
  (SELECT CASE WHEN is_called THEN last_value ELSE 0 END FROM pgmq.#{seq_name}) AS total_messages,
1341
1341
  (SELECT max(read_ct) FROM pgmq.#{qtable}) AS max_read_ct,
1342
1342
  (SELECT count(*) FROM pgmq.#{qtable} WHERE vt <= NOW() AND read_ct = 0) AS visible_unread_length,
1343
- (SELECT EXTRACT(epoch FROM (NOW() - min(vt)))::int FROM pgmq.#{qtable} WHERE vt <= NOW()) AS oldest_claimable_age_sec
1343
+ (SELECT EXTRACT(epoch FROM (NOW() - min(vt)))::int FROM pgmq.#{qtable} WHERE vt <= NOW()) AS oldest_claimable_age_sec,
1344
+ (SELECT EXTRACT(epoch FROM (NOW() - min(vt)))::int FROM pgmq.#{qtable} WHERE vt <= NOW() AND read_ct = 0) AS oldest_unread_claimable_age_sec
1344
1345
  SQL
1345
1346
  rescue StandardError => e
1346
1347
  Pgbus.logger.debug { "[Pgbus::Web] Skipping queue metrics for #{name}: #{e.message}" }
@@ -1362,7 +1363,8 @@ module Pgbus
1362
1363
  newest_msg_age_sec: row["newest_msg_age_sec"]&.to_i,
1363
1364
  total_messages: row["total_messages"].to_i,
1364
1365
  max_read_ct: row["max_read_ct"]&.to_i,
1365
- visible_unread_length: row["visible_unread_length"].to_i
1366
+ visible_unread_length: row["visible_unread_length"].to_i,
1367
+ oldest_unread_claimable_age_sec: row["oldest_unread_claimable_age_sec"]&.to_i
1366
1368
  }
1367
1369
  end
1368
1370
  rescue StandardError => e
@@ -1382,6 +1384,7 @@ module Pgbus
1382
1384
  EXTRACT(epoch FROM (NOW() - max(enqueued_at)))::int AS newest_msg_age_sec,
1383
1385
  EXTRACT(epoch FROM (NOW() - min(enqueued_at)))::int AS oldest_msg_age_sec,
1384
1386
  EXTRACT(epoch FROM (NOW() - min(vt) FILTER (WHERE vt <= NOW())))::int AS oldest_claimable_age_sec,
1387
+ EXTRACT(epoch FROM (NOW() - min(vt) FILTER (WHERE vt <= NOW() AND read_ct = 0)))::int AS oldest_unread_claimable_age_sec,
1385
1388
  max(read_ct) AS max_read_ct,
1386
1389
  count(CASE WHEN vt <= NOW() AND read_ct = 0 THEN 1 END) AS visible_unread_length
1387
1390
  FROM pgmq.#{qtable}
@@ -1398,6 +1401,7 @@ module Pgbus
1398
1401
  q_summary.oldest_claimable_age_sec,
1399
1402
  q_summary.max_read_ct,
1400
1403
  q_summary.visible_unread_length,
1404
+ q_summary.oldest_unread_claimable_age_sec,
1401
1405
  all_metrics.total_messages
1402
1406
  FROM q_summary, all_metrics
1403
1407
  SQL
@@ -1414,7 +1418,8 @@ module Pgbus
1414
1418
  newest_msg_age_sec: row["newest_msg_age_sec"]&.to_i,
1415
1419
  total_messages: row["total_messages"].to_i,
1416
1420
  max_read_ct: row["max_read_ct"]&.to_i,
1417
- visible_unread_length: row["visible_unread_length"].to_i
1421
+ visible_unread_length: row["visible_unread_length"].to_i,
1422
+ oldest_unread_claimable_age_sec: row["oldest_unread_claimable_age_sec"]&.to_i
1418
1423
  }
1419
1424
  rescue StandardError => e
1420
1425
  Pgbus.logger.error { "[Pgbus::Web] Error fetching metrics for #{queue_name}: #{e.class}: #{e.message}" }
@@ -85,6 +85,8 @@ module Pgbus
85
85
  def health_bind: () -> String
86
86
  def health_bind=: (untyped) -> untyped
87
87
  def health_port: () -> untyped
88
+ def health_unclaimed_grace: () -> untyped
89
+ def health_unclaimed_grace=: (untyped value) -> untyped
88
90
  def health_port=: (untyped) -> untyped
89
91
  def idempotency_ttl: () -> Numeric?
90
92
  def idempotency_ttl=: (untyped value) -> untyped
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.2
4
+ version: 0.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -456,10 +456,12 @@ files:
456
456
  - lib/pgbus/outbox/poller.rb
457
457
  - lib/pgbus/pgmq_schema.rb
458
458
  - lib/pgbus/pgmq_schema/fixups/pgmq_v1.13.0.sql
459
+ - lib/pgbus/pgmq_schema/fixups/pgmq_v1.13.1.sql
459
460
  - lib/pgbus/pgmq_schema/pgmq_v1.11.0.sql
460
461
  - lib/pgbus/pgmq_schema/pgmq_v1.11.1.sql
461
462
  - lib/pgbus/pgmq_schema/pgmq_v1.12.0.sql
462
463
  - lib/pgbus/pgmq_schema/pgmq_v1.13.0.sql
464
+ - lib/pgbus/pgmq_schema/pgmq_v1.13.1.sql
463
465
  - lib/pgbus/process/claim_buffer.rb
464
466
  - lib/pgbus/process/consumer.rb
465
467
  - lib/pgbus/process/consumer_priority.rb